gap> 
gap> # TestFile, by Marco Costantini, of the 'openmath' package.
gap> 
gap> # Start
gap> 
gap> START_TEST( "Test of the 'openmath' package" );
gap> SizeScreen([80]);;
gap> 
gap> 
gap> LoadPackage("openmath");
OpenMath package, by Andrew Solomon and Marco Costantini
#I  Warning: package openmath, global variable 'ViewString' overwritten
true
gap> 
gap> ## Some examples from file openmath/examples
gap> 
gap> # Example 1:
gap> 
gap> stream := InputTextFile(Filename(
>         DirectoriesPackageLibrary("openmath","tst"),"test3.omt"));;
gap> OMGetObject(stream);
912873912381273891
gap> OMGetObject(stream);
E(4)
gap> OMGetObject(stream);
true
gap> OMGetObject(stream);
false
gap> OMGetObject(stream);
"LAMBDA"
gap> OMGetObject(stream);
"dummy1"
gap> OMGetObject(stream);
"string1"
gap> OMGetObject(stream);
(1,2,3)
gap> OMGetObject(stream);
Group([ (1,2,3) ])
gap> OMGetObject(stream);
(1,2,3)
gap> 
gap> CloseStream( stream );
gap> 
gap> 
gap> # similar, for file tst/test3.bin: binary encoding
gap> 
gap> stream := InputTextFile(Filename(
>         DirectoriesPackageLibrary("openmath","tst"),"test3.bin"));;
gap> OMGetObject(stream);
912873912381273891
gap> OMGetObject(stream);
E(4)
gap> OMGetObject(stream);
true
gap> OMGetObject(stream);
false
gap> OMGetObject(stream);
"LAMBDA"
gap> OMGetObject(stream);
"dummy1"
gap> OMGetObject(stream);
"string1"
gap> OMGetObject(stream);
(1,2,3)
gap> OMGetObject(stream);
Group([ (1,2,3) ])
gap> OMGetObject(stream);
(1,2,3)
gap> 
gap> CloseStream( stream );
gap> 
gap> 
gap> # similar, for file tst/test4.out: gpipe encoding
gap> 
gap> stream := InputTextFile(Filename(
>         DirectoriesPackageLibrary("openmath","tst"),"test4.out"));;
gap> OMgetObjectByteStream(stream);
912873912381273891
gap> OMgetObjectByteStream(stream);
E(4)
gap> CloseStream( stream );
gap> 
gap> 
gap> # similar, for file tst/test5.omt
gap> 
gap> stream := InputTextFile(Filename(DirectoriesPackageLibrary("openmath","tst"),"test5.omt"));;
gap> OMGetObject(stream);
CharacterTable( Alt( [ 1 .. 3 ] ) )
gap> CloseStream( stream );
gap> 
gap> 
gap> # similar, for file tst/test6.omt
gap> 
gap> stream := InputTextFile(Filename(DirectoriesPackageLibrary("openmath","tst"),"test6.omt"));;
gap> OMGetObject(stream);
""
gap> OMGetObject(stream);
1
gap> OMGetObject(stream);
true
gap> OMGetObject(stream);
true
gap> OMGetObject(stream);
true
gap> OMGetObject(stream);
""
gap> OMGetObject(stream);
"SuPeRfail"
gap> OMGetObject(stream);
true
gap> OMGetObject(stream);
CharacterTable( "V4" )
gap> OMGetObject(stream);
true
gap> CloseStream( stream );
gap> 
gap> 
gap> # similar, for file tst/test_new.omt
gap> 
gap> stream := InputTextFile(Filename(DirectoriesPackageLibrary("openmath","tst"),"test_new.omt"));;
gap> OMGetObject(stream);
true
gap> OMGetObject(stream);
[ [ 19, 22 ], [ 43, 50 ] ]
gap> OMGetObject(stream);
6
gap> OMGetObject(stream);
9
gap> OMGetObject(stream);
1
gap> OMGetObject(stream);
E(4)
gap> OMGetObject(stream);
infinity
gap> OMGetObject(stream);
[ 3, 6, 9 ]
gap> OMGetObject(stream);
[ 3, 6, 9 ]
gap> OMGetObject(stream);
[ 3, 6, 9 ]
gap> # there are 3 objects left on stream, but they are from CD "error"
gap> CloseStream( stream );
gap> 
gap> 
gap> # Example 2:
gap> 
gap> g := SymmetricGroup(5);
Sym( [ 1 .. 5 ] )
gap> t := "";
""
gap> s := OutputTextString(t, true);
OutputTextString(0)
gap> OMPutObject(s, g);
gap> CloseStream(s);
gap> 
gap> s := InputTextString(t);
InputTextString(0,303)
gap> h := OMGetObject(s);
Group([ (1,2,3,4,5), (1,2) ])
gap> CloseStream(s);
gap> h = g;
true
gap> 
gap> 
gap> # Example 4:
gap> 
gap> g := SymmetricGroup(5);
Sym( [ 1 .. 5 ] )
gap> OMPrint(g);
<OMOBJ>
	<OMA>
		<OMS cd="group1" name="Group"/>
		<OMA>
			<OMS cd="permut1" name="Permutation"/>
			<OMI> 2</OMI>
			<OMI> 3</OMI>
			<OMI> 4</OMI>
			<OMI> 5</OMI>
			<OMI> 1</OMI>
		</OMA>
		<OMA>
			<OMS cd="permut1" name="Permutation"/>
			<OMI> 2</OMI>
			<OMI> 1</OMI>
		</OMA>
	</OMA>
</OMOBJ>
gap> 
gap> 
gap> ## test with InputTextString and binary encoding:
gap> 
gap> s := InputTextString( "\030\020\b\007\cminmax1max\020\b\004\cset1set\>\>\>\t\>\005\021\021\031" );
InputTextString(0,35)
gap> OMGetObject(s);
9
gap> CloseStream(s);
gap> 
gap> 
gap> ## test of a long object
gap> 
gap> OMTest(10^4000);
true
gap> 
gap> 
gap> ## test of escaped XML chars
gap> 
gap> s := InputTextString( "<OMOBJ> <OMSTR>&lt;&amp;&gt;&quot;&apos;</OMSTR> </OMOBJ>" );
InputTextString(0,57)
gap> OMGetObject(s);
"<&>\"'"
gap> CloseStream(s);
gap> 
gap> 
gap> ## test for the various supported objects
gap> 
gap> #I  Searching Method for OMPut with 2 arguments:
gap> #I  Total: 16 entries
gap> #I  Method 1: ``OMPut: for a range'', value: 40
gap> 
gap> OMTest([3..10]);
true
gap> OMPrint([3..10]);
<OMOBJ>
	<OMA>
		<OMS cd="interval1" name="integer_interval" />
		<OMI> 3</OMI>
		<OMI> 10</OMI>
	</OMA>
</OMOBJ>
gap> 
gap> #I  Method 2: ``OMPut: for a matrix'', value: 32
gap> 
gap> OMPrint([[11,12],[21,22]]);
<OMOBJ>
	<OMA>
		<OMS cd="linalg2" name="matrix"/>
		<OMA>
			<OMS cd="linalg2" name="matrixrow"/>
			<OMI> 11</OMI>
			<OMI> 12</OMI>
		</OMA>
		<OMA>
			<OMS cd="linalg2" name="matrixrow"/>
			<OMI> 21</OMI>
			<OMI> 22</OMI>
		</OMA>
	</OMA>
</OMOBJ>
gap> OMTest([[11,12],[21,22]]);
true
gap> 
gap> #I  Method 3: ``OMPut: for a character table'', value: 23
gap> #I  Method 4: ``OMPut: for a group'', value: 23
gap> 
gap> OMPrint(AlternatingGroup(6));
<OMOBJ>
	<OMA>
		<OMS cd="group1" name="Group"/>
		<OMA>
			<OMS cd="permut1" name="Permutation"/>
			<OMI> 2</OMI>
			<OMI> 3</OMI>
			<OMI> 4</OMI>
			<OMI> 5</OMI>
			<OMI> 1</OMI>
		</OMA>
		<OMA>
			<OMS cd="permut1" name="Permutation"/>
			<OMI> 1</OMI>
			<OMI> 2</OMI>
			<OMI> 3</OMI>
			<OMI> 5</OMI>
			<OMI> 6</OMI>
			<OMI> 4</OMI>
		</OMA>
	</OMA>
</OMOBJ>
gap> OMTest(AlternatingGroup(6));
true
gap> 
gap> #I  Method 5: ``OMPut: for an integer'', value: 20
gap> 
gap> OMPrint(10^72);
<OMOBJ>
	<OMI> 10000000000000000000000000000000000000000000000000000000000000000000000\
00</OMI>
</OMOBJ>
gap> OMTest(10^72);
true
gap> 
gap> #I  Method 6: ``OMPut: for a rational'', value: 19
gap> 
gap> OMPrint(10/72);
<OMOBJ>
	<OMA>
		<OMS cd="nums1" name="rational" />
		<OMI> 5</OMI>
		<OMI> 36</OMI>
	</OMA>
</OMOBJ>
gap> OMTest(10/72);
true
gap> 
gap> #I  Method 7: ``OMPut: for infinity'', value: 18
gap> 
gap> OMPrint(infinity);
<OMOBJ>
	<OMS cd="nums1" name="infinity" />
</OMOBJ>
gap> OMTest(infinity);
true
gap> 
gap> #I  Method 8: ``OMPut: for a proper cyclotomic'', value: 18
gap> 
gap> OMPrint(2/3+5/4*E(4));
<OMOBJ>
	<OMA>
		<OMS cd="complex1" name="complex_cartesian"/>
		<OMA>
			<OMS cd="nums1" name="rational" />
			<OMI> 2</OMI>
			<OMI> 3</OMI>
		</OMA>
		<OMA>
			<OMS cd="nums1" name="rational" />
			<OMI> 5</OMI>
			<OMI> 4</OMI>
		</OMA>
	</OMA>
</OMOBJ>
gap> OMTest(2/3+5/4*E(4));
true
gap> 
gap> #I  Method 9: ``OMPut: for a row vector'', value: 14
gap> 
gap> OMPrint([1,2,3]);
<OMOBJ>
	<OMA>
		<OMS cd="linalg2" name="vector"/>
		<OMI> 1</OMI>
		<OMI> 2</OMI>
		<OMI> 3</OMI>
	</OMA>
</OMOBJ>
gap> OMTest([1,2,3]);
true
gap> 
gap> #I  Method 10: ``OMPut: for a hasse diagram'', value: 13
gap> #I  Method 11: ``OMPut: for a set'', value: 10
gap> 
gap> OMPrint([]);
<OMOBJ>
	<OMA>
		<OMS cd="set1" name="set"/>
	</OMA>
</OMOBJ>
gap> OMTest([]);
true
gap> OMPrint(Set([true,false]));
<OMOBJ>
	<OMA>
		<OMS cd="set1" name="set"/>
		<OMS cd="logic1" name="true" />
		<OMS cd="logic1" name="false" />
	</OMA>
</OMOBJ>
gap> OMTest(Set([true,false]));
true
gap> 
gap> #I  Method 12: ``OMPut: for a permutation'', value: 10
gap> 
gap> OMPrint((1,3,5));
<OMOBJ>
	<OMA>
		<OMS cd="permut1" name="Permutation"/>
		<OMI> 3</OMI>
		<OMI> 2</OMI>
		<OMI> 5</OMI>
		<OMI> 4</OMI>
		<OMI> 1</OMI>
	</OMA>
</OMOBJ>
gap> OMTest((1,3,5));
true
gap> 
gap> #I  Method 13: ``OMPut: for a string'', value: 7
gap> 
gap> OMPrint("ciao");
<OMOBJ>
	<OMSTR>ciao</OMSTR>
</OMOBJ>
gap> OMTest("ciao");
true
gap> OMPrint(Set(['a','b']));
<OMOBJ>
	<OMSTR>ab</OMSTR>
</OMOBJ>
gap> OMTest(Set(['a','b']));
true
gap> OMPrint("");
<OMOBJ>
	<OMSTR></OMSTR>
</OMOBJ>
gap> OMTest("");
true
gap> # also the escaped XML chars
gap> OMPrint("&");
<OMOBJ>
	<OMSTR>&amp;</OMSTR>
</OMOBJ>
gap> OMTest("&");
true
gap> OMPrint("<");
<OMOBJ>
	<OMSTR>&lt;</OMSTR>
</OMOBJ>
gap> OMTest("<");
true
gap> OMPrint("<&>\"'");
<OMOBJ>
	<OMSTR>&lt;&amp;>"'</OMSTR>
</OMOBJ>
gap> OMTest("<&>\"'");
true
gap> OMPrint("&lt;&amp;");
<OMOBJ>
	<OMSTR>&amp;lt;&amp;amp;</OMSTR>
</OMOBJ>
gap> OMTest("&lt;&amp;");
true
gap> 
gap> 
gap> #I  Method 14: ``OMPut: for a function'', value: 3
gap> #I  Method 15: ``OMPut: for a boolean'', value: 3
gap> 
gap> OMPrint(false);
<OMOBJ>
	<OMS cd="logic1" name="false" />
</OMOBJ>
gap> OMTest(false);
true
gap> 
gap> #I  Method 16: ``OMPut: for a list or collection'', value: 3
gap> 
gap> OMPrint([ [ 1 .. 10 ], [  ], false, true, infinity, 1, 0 ]);
<OMOBJ>
	<OMA>
		<OMS cd="list1" name="list"/>
		<OMA>
			<OMS cd="interval1" name="integer_interval" />
			<OMI> 1</OMI>
			<OMI> 10</OMI>
		</OMA>
		<OMA>
			<OMS cd="set1" name="set"/>
		</OMA>
		<OMS cd="logic1" name="false" />
		<OMS cd="logic1" name="true" />
		<OMS cd="nums1" name="infinity" />
		<OMI> 1</OMI>
		<OMI> 0</OMI>
	</OMA>
</OMOBJ>
gap> OMTest([ [ 1 .. 10 ], [  ], false, true, infinity, 1, 0 ]);
true
gap> 
gap> 
gap> ## test of Hasse (there was a bug)
gap> 
gap> d := Domain(["0","a","b","c","1"]);
<object>
gap> Elements(d);
[ "0", "1", "a", "b", "c" ]
gap> Size(d);
5
gap> 
gap> r := BinaryRelationByElements(d,
> [ Tuple(["0","a"]),
> Tuple(["0","b"]),
> Tuple(["0","c"]),
> Tuple(["a","1"]),
> Tuple(["b","1"]),
> Tuple(["c","1"])]);
<general mapping: <object> -> <object> >
gap> 
gap> p := TransitiveClosureBinaryRelation(ReflexiveClosureBinaryRelation(r));
<general mapping: <object> -> <object> >
gap> IsPartialOrderBinaryRelation(p);
true
gap> 
gap> h := HasseDiagram(p);
<general mapping: <object> -> <object> >
gap> 
gap> # the bug was here.
gap> Elements(UnderlyingRelation(h));
[ Tuple( [ 0, a ] ), Tuple( [ 0, b ] ), Tuple( [ 0, c ] ), Tuple( [ a, 1 ] ), 
  Tuple( [ b, 1 ] ), Tuple( [ c, 1 ] ) ]
gap> 
gap> 
gap> 
gap> 
gap> ## end of test file
gap> 
gap> STOP_TEST( "test", 10000 );
Test of the 'openmath' package
GAP4stones: 9
gap> 
