|
| 1 | +criterion: |
| 2 | + bug fixes: |
| 3 | + initial: |- |
| 4 | + int multiply(int a, int b ) { |
| 5 | + int m = a * b; |
| 6 | + } |
| 7 | + answer: |- |
| 8 | + int multiply(int a, int b ) { |
| 9 | + int m = a * b; |
| 10 | + return m; |
| 11 | + } |
| 12 | + fixture: |- |
| 13 | + #include <criterion/criterion.h> |
| 14 | + int multiply(int,int); |
| 15 | +
|
| 16 | + Test(the_multiply_function, should_pass_all_the_tests_provided) { |
| 17 | + cr_assert_eq(multiply(1, 1), 1); |
| 18 | + cr_assert_eq(multiply(2, 3), 6); |
| 19 | + cr_assert_eq(multiply(3, 2), 6); |
| 20 | + cr_assert_eq(multiply(3, 5), 15); |
| 21 | + cr_assert_eq(multiply(3, 5), 15); |
| 22 | + cr_assert_eq(multiply(4, 7), 28); |
| 23 | + cr_assert_eq(multiply(7, 4), 28); |
| 24 | + cr_assert_eq(multiply(7, 0), 0); |
| 25 | + } |
| 26 | + algorithms: |
| 27 | + initial: |- |
| 28 | + // check whether an input alphabet is a vowel or not. |
| 29 | + // it should return 1 if it is a vovel, 0 if not. |
| 30 | + int is_vowel(char a) |
| 31 | + { |
| 32 | + } |
| 33 | + answer: |- |
| 34 | + int is_vowel(char a) |
| 35 | + { |
| 36 | + if (a >= 'A' && a <= 'Z') |
| 37 | + a = a + 'a' - 'A'; |
| 38 | +
|
| 39 | + if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') |
| 40 | + return 1; |
| 41 | +
|
| 42 | + return 0; |
| 43 | + } |
| 44 | + fixture: |- |
| 45 | + #include <criterion/criterion.h> |
| 46 | + int is_vowel(char a); |
| 47 | +
|
| 48 | + Test(is_vowel, should_pass_all_the_tests_provided) { |
| 49 | + cr_assert(is_vowel('a')); |
| 50 | + cr_assert(is_vowel('A')); |
| 51 | + cr_assert(is_vowel('i')); |
| 52 | + cr_assert(is_vowel('O')); |
| 53 | + cr_assert_not(is_vowel('Z')); |
| 54 | + cr_assert_not(is_vowel('s')); |
| 55 | + cr_assert_not(is_vowel('d')); |
| 56 | + cr_assert_not(is_vowel('0')); |
| 57 | + cr_assert_not(is_vowel('?')); |
| 58 | + cr_assert_not(is_vowel('=')); |
| 59 | + cr_assert_not(is_vowel('\n')); |
| 60 | + cr_assert_not(is_vowel('_')); |
| 61 | + cr_assert_not(is_vowel('>')); |
| 62 | + } |
0 commit comments