-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuleTest.c
More file actions
49 lines (44 loc) · 1.17 KB
/
Copy pathRuleTest.c
File metadata and controls
49 lines (44 loc) · 1.17 KB
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
#include "RuleTest.h"
RuleTest_t *ruleTestConstruct()
{
RuleTest_t *newRuleTest = (RuleTest_t *)malloc(sizeof(RuleTest_t));
if(newRuleTest == NULL)
{
printf("Not enough memory");
exit(0);
}
newRuleTest->attributeIndex = -1;
newRuleTest->value = NULL;
newRuleTest->next = NULL;
return newRuleTest;
}
RuleTest_t *addRuleTest(RuleTest_t *lastRuleTest, struct PrismRule *rule)
{
if(rule->ruleTest == NULL)
{
rule->ruleTest = ruleTestConstruct();
return rule->ruleTest;
}
lastRuleTest->next = ruleTestConstruct();
return lastRuleTest->next;
}
int satisfies(RuleTest_t *ruleTest, Instance_t *instance)
{
Attribute_t *attribute = getAttribute(instance, ruleTest->attributeIndex);
if(attribute->value == ruleTest->value)
{
if(ruleTest->next == NULL)
return 1;
else
return satisfies(ruleTest->next, instance);
}
return 0;
}
int isMentioned(int attributeIndex, RuleTest_t *ruleTest)
{
if(ruleTest == NULL)
return 0;
if(ruleTest->attributeIndex == attributeIndex)
return 1;
return isMentioned(attributeIndex, ruleTest->next);
}