blob: 24796e908f6d0f4d44e9e197de4d84f60526a0ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include "../puzzles/puzzle.h"
extern size_t deriveDifficuty(Puzzle *puzzle);
// we can't use the global version since we don't strdup here
void free_puzzle(Puzzle *p) {
if (p == NULL) return;
if (p->Tests != NULL) free(p->Tests);
free(p);
}
char *difficultyCalculator() {
Puzzle *simple_puzzle = malloc(sizeof(Puzzle));
if (simple_puzzle == NULL) return "Puzzle allocation failed";
simple_puzzle->TestC = 2;
simple_puzzle->Tests = malloc(sizeof(Test) * 2);
if (simple_puzzle->Tests == NULL) return "Test array allocation failed";
simple_puzzle->Tests[0].MainMethodSignature = "sig";
simple_puzzle->Tests[0].RecieverName = "rec";
simple_puzzle->Tests[1].MainMethodSignature = "sig";
simple_puzzle->Tests[1].RecieverName = "rec";
size_t calcualted_diff = deriveDifficuty(simple_puzzle);
if (calcualted_diff != 2) {
free_puzzle(simple_puzzle);
printf("Got: %zu, expected: %d\n", calcualted_diff, 2);
return "The difficulty calculation for puzzles with one method is incorrect";
}
simple_puzzle->Tests[1].MainMethodSignature = "sig1";
calcualted_diff = deriveDifficuty(simple_puzzle);
if (calcualted_diff != 4) {
free_puzzle(simple_puzzle);
printf("Got: %zu, expected: %d\n", calcualted_diff, 4);
return "The difficulty calculation for puzzles with two methods (different signature) is incorrect";
}
simple_puzzle->Tests[1].MainMethodSignature = "sig";
simple_puzzle->Tests[1].RecieverName = "re1";
calcualted_diff = deriveDifficuty(simple_puzzle);
if (calcualted_diff != 4) {
free_puzzle(simple_puzzle);
printf("Got: %zu, expected: %d\n", calcualted_diff, 4);
return "The difficulty calculation for puzzles with two methods (different recievers) is incorrect";
}
// FreePuzzle(simple_puzzle);
free_puzzle(simple_puzzle);
return NULL;
}
|