Cody

# Problem 44437. How many days in a month?

Solution 2772277

Submitted on 3 Aug 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('daysInMonth.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden') assert(isempty(strfind(filetext, 'if')),'IF statements are forbidden')

2   Pass
m = 1; d_correct = 31; assert(isequal(daysInMonth(m),d_correct))

d = 31

3   Pass
m = 2; d_correct = 28; assert(isequal(daysInMonth(m),d_correct))

d = 28

4   Pass
m = 3; d_correct = 31; assert(isequal(daysInMonth(m),d_correct))

d = 31

5   Pass
m = 4; d_correct = 30; assert(isequal(daysInMonth(m),d_correct))

d = 30

6   Pass
m = 5; d_correct = 31; assert(isequal(daysInMonth(m),d_correct))

d = 31

7   Pass
m = 6; d_correct = 30; assert(isequal(daysInMonth(m),d_correct))

d = 30

8   Pass
m = 7; d_correct = 31; assert(isequal(daysInMonth(m),d_correct))

d = 31

9   Pass
m = 8; d_correct = 31; assert(isequal(daysInMonth(m),d_correct))

d = 31

10   Pass
m = 9; d_correct = 30; assert(isequal(daysInMonth(m),d_correct))

d = 30

11   Pass
m = 10; d_correct = 31; assert(isequal(daysInMonth(m),d_correct))

d = 31

12   Pass
m = 11; d_correct = 30; assert(isequal(daysInMonth(m),d_correct))

d = 30

13   Pass
m = 12; d_correct = 31; assert(isequal(daysInMonth(m),d_correct))

d = 31

14   Fail
m = 13; d_correct = -1; assert(isequal(daysInMonth(m),d_correct))

Error using calendar (line 27) MONTH must contain values between 1 and 12. Error in daysInMonth (line 2) d = max(calendar(2017,m),[],'all') Error in Test14 (line 3) assert(isequal(daysInMonth(m),d_correct))

15   Fail
m = randi([-100 0]); d_correct = -1; assert(isequal(daysInMonth(m),d_correct))

Error using calendar (line 27) MONTH must contain values between 1 and 12. Error in daysInMonth (line 2) d = max(calendar(2017,m),[],'all') Error in Test15 (line 3) assert(isequal(daysInMonth(m),d_correct))