1 | #include <iostream> |
---|
2 | #include <sstream> |
---|
3 | |
---|
4 | #include <stdlib.h> |
---|
5 | |
---|
6 | #include "test_iparith.hpp" |
---|
7 | #include <kernel/mod2.h> |
---|
8 | #include <Singular/grammar.h> |
---|
9 | #include <Singular/ipid.h> |
---|
10 | |
---|
11 | using namespace Singular::tests; |
---|
12 | |
---|
13 | CPPUNIT_TEST_SUITE_REGISTRATION( Singular::tests::IpArithTest ); |
---|
14 | |
---|
15 | extern int iiInitArithmetic(); |
---|
16 | extern int iiArithAddItem2list(void **list, long *item_count, long sizeofitem, |
---|
17 | void *newitem); |
---|
18 | extern int iiArithFindCmd(const char *szName); |
---|
19 | extern char *iiArithGetCmd( int nPos ); |
---|
20 | extern int iiArithRemoveCmd(const char *szName); |
---|
21 | extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval, |
---|
22 | short nToktype, short nPos); |
---|
23 | |
---|
24 | /* To be tested |
---|
25 | |
---|
26 | static BOOLEAN jjBREAK0(leftv res, leftv v) |
---|
27 | static BOOLEAN jjBREAK1(leftv res, leftv v) |
---|
28 | static BOOLEAN jjCALL1ARG(leftv res, leftv v) |
---|
29 | static BOOLEAN jjCALL2ARG(leftv res, leftv u) |
---|
30 | static BOOLEAN jjCALL3ARG(leftv res, leftv u) |
---|
31 | static BOOLEAN jjCOEF_M(leftv res, leftv v) |
---|
32 | static BOOLEAN jjDIVISION4(leftv res, leftv v) |
---|
33 | static BOOLEAN jjIDEAL_PL(leftv res, leftv v) |
---|
34 | static BOOLEAN jjINTERSECT_PL(leftv res, leftv v) |
---|
35 | static BOOLEAN jjINTVEC_PL(leftv res, leftv v) |
---|
36 | static BOOLEAN jjJET4(leftv res, leftv u) |
---|
37 | static BOOLEAN jjKLAMMER_PL(leftv res, leftv u) |
---|
38 | static BOOLEAN jjLIST_PL(leftv res, leftv v) |
---|
39 | static BOOLEAN jjNAMES0(leftv res, leftv v) |
---|
40 | static BOOLEAN jjOPTION_PL(leftv res, leftv v) |
---|
41 | static BOOLEAN jjREDUCE4(leftv res, leftv u) |
---|
42 | static BOOLEAN jjREDUCE5(leftv res, leftv u) |
---|
43 | static BOOLEAN jjRESERVED0(leftv res, leftv v) |
---|
44 | static BOOLEAN jjSTRING_PL(leftv res, leftv v) |
---|
45 | static BOOLEAN jjSTATUS_M(leftv res, leftv v) |
---|
46 | static BOOLEAN jjSUBST_M(leftv res, leftv u) |
---|
47 | static BOOLEAN jjSTD_HILB_WP(leftv res, leftv INPUT) |
---|
48 | |
---|
49 | BOOLEAN iiExprArith2(lef |
---|
50 | tv res, leftv a, int op, leftv b, BOOLEAN proccall) |
---|
51 | BOOLEAN iiExprArith1(leftv res, leftv a, int op) |
---|
52 | BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c) |
---|
53 | BOOLEAN jjANY2LIST(leftv res, leftv v, int cnt) |
---|
54 | BOOLEAN iiExprArithM(leftv res, leftv a, int op) |
---|
55 | int IsCmd(const char *n, int & tok) |
---|
56 | static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op) |
---|
57 | const char * Tok2Cmdname(int tok) |
---|
58 | static int _gentable_sort_cmds( const void *a, const void *b ) |
---|
59 | int iiInitArithmetic() |
---|
60 | int iiArithAddItem2list(void **list, long *item_count, long sizeofitem, void *newitem) |
---|
61 | int iiArithFindCmd(const char *szName) |
---|
62 | char *iiArithGetCmd( int nPos ) |
---|
63 | int iiArithRemoveCmd(const char *szName) |
---|
64 | int iiArithAddCmd(const char *szName, short nAlias, short nTokval, |
---|
65 | short nToktype, short nPos ) |
---|
66 | |
---|
67 | GENTABLE |
---|
68 | void ttGen1() |
---|
69 | void ttGen2b() |
---|
70 | void ttGen4() |
---|
71 | const char * Tok2Cmdname(int tok) |
---|
72 | short IsCmdToken(short tok) |
---|
73 | */ |
---|
74 | void IpArithTest::setUp() { |
---|
75 | iiInitArithmetic(); |
---|
76 | } |
---|
77 | |
---|
78 | void IpArithTest::tearDown() { |
---|
79 | } |
---|
80 | |
---|
81 | void IpArithTest::test_iiArithFindCmd() |
---|
82 | { |
---|
83 | const char *name = "LIB"; |
---|
84 | double fStart = Time(); |
---|
85 | int pos = iiArithFindCmd(name); |
---|
86 | double fEnd = Time(); |
---|
87 | |
---|
88 | printf("Time: %f\n", fEnd-fStart); |
---|
89 | CPPUNIT_ASSERT(std::string(name) == std::string(iiArithGetCmd(pos))); |
---|
90 | |
---|
91 | const char * name2 = "nix"; |
---|
92 | pos = iiArithFindCmd(name2); |
---|
93 | CPPUNIT_ASSERT(pos==-1); |
---|
94 | |
---|
95 | return; |
---|
96 | } |
---|
97 | |
---|
98 | void IpArithTest::test_Timing1() |
---|
99 | { |
---|
100 | double fStart; |
---|
101 | double fEnd; |
---|
102 | int nMax = 0; |
---|
103 | |
---|
104 | fStart = Time(); |
---|
105 | while(iiArithGetCmd(nMax)!=NULL) nMax++; |
---|
106 | fEnd = Time(); |
---|
107 | printf("Find sizeof sArithBase Time: %f %f %f\n", fEnd, fStart, fEnd-fStart); |
---|
108 | |
---|
109 | fStart = Time(); |
---|
110 | for(int i=0; i<1000000; i++) { |
---|
111 | int pos = random() % nMax; |
---|
112 | CPPUNIT_ASSERT(iiArithGetCmd(pos)!=NULL); |
---|
113 | |
---|
114 | } |
---|
115 | fEnd = Time(); |
---|
116 | printf("Find sizeof iiArithGetCmd 1000000 loop Time: %f\n", fEnd-fStart); |
---|
117 | |
---|
118 | fStart = Time(); |
---|
119 | int rc = iiArithAddCmd("TestCMD2", 0, 999, 0, -1); |
---|
120 | fEnd = Time(); |
---|
121 | printf("Add rc=%d - %f\n", rc, fEnd-fStart); |
---|
122 | CPPUNIT_ASSERT_EQUAL(0, rc); |
---|
123 | CPPUNIT_ASSERT(0 != iiArithAddCmd("TestCMD2", 0, 999, 0, -1)); |
---|
124 | fStart = Time(); |
---|
125 | iiArithRemoveCmd("TestCMD2"); |
---|
126 | fEnd = Time(); |
---|
127 | printf("Remove rc=%d - %f\n", rc, fEnd-fStart); |
---|
128 | |
---|
129 | fStart = Time(); |
---|
130 | rc = iiArithAddCmd("ATestCMD2", 0, 998, 0, -1); |
---|
131 | fEnd = Time(); |
---|
132 | printf("Add rc=%d - %f\n", rc, fEnd-fStart); |
---|
133 | CPPUNIT_ASSERT_EQUAL(0, rc); |
---|
134 | CPPUNIT_ASSERT(0 != iiArithAddCmd("ATestCMD2", 0, 998, 0, -1)); |
---|
135 | |
---|
136 | |
---|
137 | fStart = Time(); |
---|
138 | for(int i=0; i<10000; i++) { |
---|
139 | int pos = random() % nMax; |
---|
140 | CPPUNIT_ASSERT_EQUAL(0, iiArithAddCmd("TestCMD", 0, 999, 0, -1)); |
---|
141 | iiArithRemoveCmd("TestCMD"); |
---|
142 | } |
---|
143 | fEnd = Time(); |
---|
144 | printf("Find sizeof iiArithAdd/RemoveCmd 10000 loop Time: %f\n", fEnd-fStart); |
---|
145 | |
---|
146 | // end of performance test |
---|
147 | printf("Time: %f\n", fEnd-fStart); |
---|
148 | return; |
---|
149 | } |
---|