1 package org.lsmp.djepJUnit; 2 3 import junit.framework.*; 4 import org.nfunk.jep.*; 5 import org.nfunk.jep.type.*; 6 import org.lsmp.djep.groupJep.interfaces.*; 7 import org.lsmp.djep.groupJep.values.*; 8 import org.lsmp.djep.groupJep.*; 9 import org.lsmp.djep.groupJep.groups.*; 10 import java.math.*; 11 18 19 25 public class GroupJepTest extends TestCase { 26 GroupJep j; 27 public static final boolean SHOW_BAD=false; 28 29 public GroupJepTest(String name) { 30 super(name); 31 } 32 33 public static void main(String args[]) { 34 36 TestSuite suite= new TestSuite(GroupJepTest.class); 37 suite.run(new TestResult()); 40 } 41 42 protected void setUp() { 43 } 44 45 public static Test suite() { 46 return new TestSuite(GroupJepTest.class); 47 } 48 49 public void myAssertEquals(String msg,String actual,String expected) 50 { 51 if(!actual.equals(expected)) 52 System.out.println("Error \""+msg+"\" is \""+actual+" should be "+expected+"\""); 53 assertEquals("<"+msg+">",expected,actual); 54 System.out.println("Success: Value of \""+msg+"\" is \""+actual+"\""); 55 } 56 57 public void myAssertEquals(String msg,String actual,String expected,String ending) 58 { 59 if(!actual.equals(expected)) 60 System.out.println("Error \""+msg+"\" is \""+actual+" should be "+expected+"\""); 61 assertEquals("<"+msg+">",expected,actual); 62 System.out.println("Success: Value of \""+msg+"\" is \""+actual+"\": "+ending); 63 } 64 65 66 public void testGood() 67 { 68 assertEquals(1,1); 69 } 70 71 public void valueToStringTest(String expr,String expected) throws Exception 72 { 73 Node node = j.parse(expr); 74 Object val = j.evaluate(node); 75 String res = val.toString(); 76 String ending=""; 77 if(val instanceof HasComplexValueI) 78 { 79 Complex cval = ((HasComplexValueI) val).getComplexValue(); 80 ending = cval.toString(); 81 } 82 myAssertEquals(expr,res,expected,ending); 83 } 84 85 86 public void testZ() throws Exception 87 { 88 j = new GroupJep(new Integers()); 89 valueToStringTest("1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20","2432902008176640000"); 90 } 91 92 93 public void testQ() throws Exception 94 { 95 j = new GroupJep(new Rationals()); 96 System.out.println(j.getGroup().toString()); 97 valueToStringTest("(1/2)-(1/3)","1/6"); 98 } 99 100 101 public void testQuartonians() throws Exception 102 { 103 j = new GroupJep(new Quartonians()); 104 j.addStandardConstants(); 105 System.out.println(j.getGroup().toString()); 106 valueToStringTest("i*j","0.0+0.0 i +0.0 j +-1.0 k"); 107 } 108 109 110 public void testZn() throws Exception 111 { 112 j = new GroupJep(new Zn(BigInteger.valueOf(5))); 113 System.out.println(j.getGroup().toString()); 114 valueToStringTest("2*3","1"); 115 valueToStringTest("2*4","3"); 116 valueToStringTest("3*3","4"); 117 valueToStringTest("3*4","2"); 118 valueToStringTest("4*4","1"); 119 120 valueToStringTest("2/3","4"); 121 valueToStringTest("2/4","3"); 122 valueToStringTest("3/2","4"); 123 valueToStringTest("3/4","2"); 124 valueToStringTest("4/2","2"); 125 valueToStringTest("4/3","3"); 126 } 127 128 public void testZroot2() throws Exception 129 { 130 RingI ring = new Integers(); 131 Number coeffs[] = new Number []{ 132 BigInteger.valueOf(-2), 133 BigInteger.ZERO, 134 BigInteger.ONE}; 135 Polynomial p1 = new Polynomial(ring,"rt2",coeffs); 136 137 j = new GroupJep(new AlgebraicExtension(ring, p1)); 138 j.addStandardConstants(); 139 System.out.println(j.getGroup().toString()); 140 valueToStringTest("rt2*rt2","<2>"); 141 valueToStringTest("(rt2+1)*(rt2+1)","<2 rt2+3>"); 142 } 143 144 public void testZ5thRootUnity() throws Exception 145 { 146 RingI ring = new Integers(); 147 Number coeffs[] = new Number []{ 148 BigInteger.valueOf(-1), 149 BigInteger.ZERO, 150 BigInteger.ZERO, 151 BigInteger.ZERO, 152 BigInteger.ZERO, 153 BigInteger.ONE}; 154 Polynomial p1 = new Polynomial(ring,"t",coeffs); 155 156 j = new GroupJep(new AlgebraicExtension(ring, p1)); 157 j.addStandardConstants(); 158 System.out.println(j.getGroup().toString()); 159 valueToStringTest("t*t","<t^2>"); 160 valueToStringTest("t*t*t","<t^3>"); 161 valueToStringTest("t*t*t*t","<t^4>"); 162 valueToStringTest("t*t*t*t*t","<1>"); 163 } 164 165 public void testZRoot2Root5() throws Exception 166 { 167 RingI ring = new Integers(); 168 Number coeffs1[] = new Number []{ 169 BigInteger.valueOf(-2), 170 BigInteger.ZERO, 171 BigInteger.ONE}; 172 Polynomial p1 = new Polynomial(ring,"t",coeffs1); 173 AlgebraicExtension an1 = new AlgebraicExtension(ring, p1); 174 175 Number coeffs2[] = new Number []{ 176 an1.valueOf("-5"), 177 an1.valueOf("0"), 178 an1.valueOf("1")}; 179 Polynomial p2 = new Polynomial(an1,"s",coeffs2); 180 AlgebraicExtension an2 = new AlgebraicExtension(an1, p2); 181 182 j = new GroupJep(an2); 183 j.addStandardConstants(); 184 System.out.println(j.getGroup().toString()); 185 186 valueToStringTest("t","<t>"); 187 valueToStringTest("s","<s>"); 188 valueToStringTest("t*t","<2>"); 189 valueToStringTest("s*s","<5>"); 190 valueToStringTest("s*t","<t s>"); 191 valueToStringTest("s+t","<s+t>"); 192 valueToStringTest("(t-1)*(s-1)","<<t-1> s+-t+1>"); 193 } 194 195 public void testZtau() throws Exception 196 { 197 RingI ring = new Integers(); 198 Number coeffs[] = new Number []{ 199 BigInteger.valueOf(-1), 200 BigInteger.valueOf(-1), 201 BigInteger.ONE}; 202 Polynomial p1 = new Polynomial(ring,"t",coeffs); 203 204 AlgebraicExtension an = new AlgebraicExtension(ring, p1); 205 j = new GroupJep(an); 206 j.addStandardConstants(); 207 j.setAllowAssignment(true); 208 j.setAllowUndeclared(true); 209 System.out.println(j.getGroup().toString()); 210 valueToStringTest("t*t","<t+1>"); 211 valueToStringTest("t*t*t","<2 t+1>"); 212 valueToStringTest("t*t*t*t","<3 t+2>"); 213 valueToStringTest("t*t*t*t*t","<5 t+3>"); 214 valueToStringTest("t*t*t*t*t*t","<8 t+5>"); 215 valueToStringTest("x=2*t-1","<2 t-1>"); 216 valueToStringTest("x*x","<5>"); 217 valueToStringTest("-t","<-t>"); 218 valueToStringTest("1-t","<-t+1>"); 219 valueToStringTest("t*(1-t)","<-1>"); 220 } 221 222 public void testBad() throws ParseException 223 { 224 if(SHOW_BAD) 225 { 226 } 234 } 235 } 236 | Popular Tags |