-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_Cmd_Interface.cpp
executable file
·135 lines (126 loc) · 3.88 KB
/
test_Cmd_Interface.cpp
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
131
132
133
134
135
//
// test_Cmd_Interface.cpp
//
// Created by Lu Yi on 11/8/12.
// Copyright 2011 UC Davis. All rights reserved.
//
#include <iostream>
#include <ctime>
#include "Grammer_analysis.h"
#include "helper.h"
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
using namespace std;
void bufferTest();
int LinkedListTest();
int ListNodeTest();
void seperateWordTest();
int main(void){
clock_t tik,tak;
tik = clock();
std::cout << "Trying to connect to database webster.db...";
sqlite3 *db;
sqlite3_stmt *statement;
string sql_cmd = "";
const char *tail;
int DB_FAILED = 0;
DB_FAILED = sqlite3_open("webster.db", &db);
if (DB_FAILED) {cout << "Failed.\n";}else{cout << "Succeeded.\n";}
ListNodeTest();
LinkedListTest();
GWord apple("apple");
bufferTest();
apple.display();
tak = clock();
std::cout << "Time cost: " << 1000*(double)(tak - tik)/CLOCKS_PER_SEC << "ms." << std::endl;
return EXIT_SUCCESS;
}
void bufferTest(){
bool quit_flag = false;
//char ** ptr;
std::string inputBuffer = "";
std::cout << "\n\n************************************************\nWelcome to the grammer helper test interface!\nThis interface is for test only!\n************************************************\nPlease input a complete sentence or phrase for testing:\n\n";
GSentence test;
while (!quit_flag) {
std::cout << "Test_input> ";
std::getline(std::cin, inputBuffer);
if (inputBuffer == "q" || inputBuffer == "Q"){
quit_flag = true;
break;
}
if (quit_flag == false) {
test.make_empty();
test.get_sentence(inputBuffer);
//std::cout << "Finish scanning!\n";
std::cout << "Total elements of buffer: " << test.length() << "\nTotal word: " << test.wordsCount() << "\nTotal symbols: " << test.symbolsCount() << std::endl;
// test.printList();
//todo fix printList();
}
}
}
int ListNodeTest(){
std::cout << "Testing ListNode..............\n";
std::cout << "This is a test, lol!\n";
try {
GListNode thisN("This");
GListNode is("is");
GListNode a("a");
GListNode test("test");
GListNode s1(',');
GListNode lol("lol");
GListNode punc('!');
thisN.setPtr(&is);
is.setPtr(&a);
a.setPtr(&test);
test.setPtr(&s1);
s1.setPtr(&lol);
lol.setPtr(&punc);
GListNode * currentPtr = &thisN;
while (currentPtr != 0) {
std::cout << currentPtr->content();
if (currentPtr->nextPointer() != 0)
if (currentPtr->nextPointer()->GIdentifier() == id_GListNode_GWord)
std::cout << " ";
currentPtr = currentPtr->nextPointer();
}
std::cout << std::endl;
}catch(int){
std::cout << "error occured.\n";
return EXIT_FAILURE;
}
std::cout << "Test for list node done. All good!\n";
return EXIT_SUCCESS;
}
int LinkedListTest(){
std::cout << "Test for linked list begin.\n";
std::cout << "This is a test, lol!\n";
try {
GLinkedList test;
test.addNode("This");
test.addNode("is");
test.addNode("a");
test.addNode("test");
test.addNode(',');
test.addNode("lol");
test.addNode('!');
// test.printList();
//todo fix printList();
test[0].setContent("That");
// test.printList();
//todo fix printList();
test[1];
test[2];
test[3];
test[4];
test[5];
test[6];
std::cout << "Total nodes: " << test.length() << std::endl;
std::cout << "Total words: " << test.wordsCount() << std::endl;
std::cout << "Total symbols: " << test.symbolsCount() << std::endl;
} catch (int) {
std::cout << "Error occured.\n";
return EXIT_FAILURE;
}
std::cout << "Test for linked list done. All good!\n";
return EXIT_SUCCESS;
}