-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_engine.c
132 lines (90 loc) · 3.16 KB
/
test_engine.c
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/**
Simple tests
1) copy (link) example data files and test_engine.c to a new dir, say "engine"
2) cd to say "engine"
3) copy files from repo to "engine"
4) Generate executable using the following command
% gcc -Wall -Werror -lm -std=c11 *.c -o engine
5) Run
% ./engine
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "invertedIndex.h"
/** Util function below ...
*/
void printTfIdfList(char *filename, TfIdfList list){
FILE *fp = fopen(filename, "w");
if( fp == NULL ) {
printf("Error opening file : %s \n", filename );
return;
}
TfIdfList cur = list;
while(cur != NULL) {
fprintf(fp, "%.6f %s\n", cur->tfidf_sum, cur->filename );
cur = cur->next;
}
fclose(fp);
}
void checkNormalisedString(char *origString, char *answerString){
char originalString[100];
char *stuString;
strcpy(originalString, origString);
stuString = normaliseWord(originalString);
if( (originalString == stuString) &&
(strcmp(stuString, answerString) == 0) ){
printf("> Test Passed: %s to %s\n", origString, stuString);
}
else {
printf("> Test Failed: %s to %s [Expected %s]\n", origString, stuString, answerString);
}
}
void testNormalise(){
printf("Testing function normaliseWord \n");
checkNormalisedString(".Net", ".net");
checkNormalisedString("smh.com.au", "smh.com.au");
checkNormalisedString("Sydney!", "sydney!");
checkNormalisedString("wHy?", "why");
checkNormalisedString("ORDER.", "order");
checkNormalisedString("Text;", "text");
checkNormalisedString("abc.net.au.", "abc.net.au");
checkNormalisedString("Sydney???", "sydney??");
}
int main (int argc, char *argv[]) {
// ========= Part-1 Testing =========
testNormalise();
// ---------------------------------------------------------
InvertedIndexBST invertedTree = generateInvertedIndex("collection.txt");
/** Your output in "invertedIndex.txt" should be
same as the expected answer in "invertedIndex_exp.txt"
*/
printInvertedIndex(invertedTree);
// ========= Part-2 Testing =========
TfIdfList list = calculateTfIdf(invertedTree, "mars" , 7);
/** Your output in "mars_TfIdfList.txt" should be
same as the expected answer in "mars_TfIdfList_exp.txt"
*/
printTfIdfList("mars_TfIdfList.txt" , list);
TfIdfList list_sun = calculateTfIdf(invertedTree, "sun" , 7);
/** Your output in "sun_TfIdfList.txt" should be
same as the expected answer in "sun_TfIdfList_exp.txt"
*/
printTfIdfList("sun_TfIdfList.txt" , list_sun);
TfIdfList list_moon = calculateTfIdf(invertedTree, "moon" , 7);
printTfIdfList("moon_TfIdfList.txt" , list_moon );
// ---------------------------------------------------------
/** ----- The following will be available over the weekend -----
*/
char *words[] = { "nasa", "mars", "moon", NULL };
TfIdfList listM = retrieve(invertedTree, words , 7);
/** Your output in "nasa_mars_moon.txt" should be
same as the expected answer in "nasa_mars_moon.txt_exp.txt"
*/
printTfIdfList("nasa_mars_moon.txt" , listM);
/*
A "free" function to free "invertedTree" and the related memory,
and call it here. The function is not currently developed.
*/
return 0;
}