source: git/tests/Singular/test_iparith.cpp @ 6ce030f

spielwiese
Last change on this file since 6ce030f was 383b2c8, checked in by Oleksandr Motsak <motsak@…>, 12 years ago
CHG: mod2.h should better be included as <kernel/mod2.h>
  • Property mode set to 100644
File size: 4.5 KB
Line 
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
11using namespace Singular::tests;
12
13CPPUNIT_TEST_SUITE_REGISTRATION( Singular::tests::IpArithTest );
14
15extern int iiInitArithmetic();
16extern int iiArithAddItem2list(void **list, long  *item_count, long sizeofitem,
17                               void *newitem);
18extern int iiArithFindCmd(const char *szName);
19extern char *iiArithGetCmd( int nPos );
20extern int iiArithRemoveCmd(const char *szName);
21extern int iiArithAddCmd(const char *szName, short nAlias, short nTokval,
22                         short nToktype, short nPos);
23
24/* To be tested
25
26static BOOLEAN jjBREAK0(leftv res, leftv v)
27static BOOLEAN jjBREAK1(leftv res, leftv v)
28static BOOLEAN jjCALL1ARG(leftv res, leftv v)
29static BOOLEAN jjCALL2ARG(leftv res, leftv u)
30static BOOLEAN jjCALL3ARG(leftv res, leftv u)
31static BOOLEAN jjCOEF_M(leftv res, leftv v)
32static BOOLEAN jjDIVISION4(leftv res, leftv v)
33static BOOLEAN jjIDEAL_PL(leftv res, leftv v)
34static BOOLEAN jjINTERSECT_PL(leftv res, leftv v)
35static BOOLEAN jjINTVEC_PL(leftv res, leftv v)
36static BOOLEAN jjJET4(leftv res, leftv u)
37static BOOLEAN jjKLAMMER_PL(leftv res, leftv u)
38static BOOLEAN jjLIST_PL(leftv res, leftv v)
39static BOOLEAN jjNAMES0(leftv res, leftv v)
40static BOOLEAN jjOPTION_PL(leftv res, leftv v)
41static BOOLEAN jjREDUCE4(leftv res, leftv u)
42static BOOLEAN jjREDUCE5(leftv res, leftv u)
43static BOOLEAN jjRESERVED0(leftv res, leftv v)
44static BOOLEAN jjSTRING_PL(leftv res, leftv v)
45static BOOLEAN jjSTATUS_M(leftv res, leftv v)
46static BOOLEAN jjSUBST_M(leftv res, leftv u)
47static BOOLEAN jjSTD_HILB_WP(leftv res, leftv INPUT)
48
49BOOLEAN iiExprArith2(lef
50tv res, leftv a, int op, leftv b, BOOLEAN proccall)
51BOOLEAN iiExprArith1(leftv res, leftv a, int op)
52BOOLEAN iiExprArith3(leftv res, int op, leftv a, leftv b, leftv c)
53BOOLEAN jjANY2LIST(leftv res, leftv v, int cnt)
54BOOLEAN iiExprArithM(leftv res, leftv a, int op)
55int IsCmd(const char *n, int & tok)
56static int iiTabIndex(const jjValCmdTab dArithTab, const int len, const int op)
57const char * Tok2Cmdname(int tok)
58static int _gentable_sort_cmds( const void *a, const void *b )
59int iiInitArithmetic()
60int iiArithAddItem2list(void **list, long  *item_count, long sizeofitem, void *newitem)
61int iiArithFindCmd(const char *szName)
62char *iiArithGetCmd( int nPos )
63int iiArithRemoveCmd(const char *szName)
64int iiArithAddCmd(const char *szName, short nAlias, short nTokval,
65                  short nToktype, short nPos )
66
67GENTABLE
68void ttGen1()
69void ttGen2b()
70void ttGen4()
71const char * Tok2Cmdname(int tok)
72short IsCmdToken(short tok)
73 */
74void IpArithTest::setUp() {
75  iiInitArithmetic();
76}
77
78void IpArithTest::tearDown() {
79}
80
81void 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
98void 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}
Note: See TracBrowser for help on using the repository browser.