Skip to content
This repository was archived by the owner on Oct 14, 2020. It is now read-only.

Commit c7c7084

Browse files
authored
Merge pull request #251 from pibi/C_tests
C examples
2 parents 1410c94 + 98ead76 commit c7c7084

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

examples/c.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
}

test/runners/c_spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var runner = require('../runner');
33

44
describe('c runner', function() {
55
describe('.run', function() {
6+
runner.assertCodeExamples('c');
7+
68
it('should handle basic code evaluation', function(done) {
79
var solution = `
810
#include <stdio.h>

0 commit comments

Comments
 (0)