Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
edadma committed Apr 2, 2018
1 parent 66ae504 commit b8cc11d
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ libraryDependencies ++= {
libraryDependencies ++= Seq(
)

coverageExcludedPackages := ".*BDF;.*Machine;.*StdIOInt;.*StdIOHex;.*JLineInt;.*JLineHex;.*RNG;.*WriteOnlyDevice;.*ReadOnlyDevice;.*Device;.*RAM;.*ROM;.*Memory;.*Addressable;.*Video;.*Options;.*Main;.*Disk;.*Hexdump"
coverageExcludedPackages := ".*BDF;.*Machine;.*StdIOChar;.*StdIOInt;.*StdIOHex;.*JLineInt;.*JLineHex;.*RNG;.*WriteOnlyDevice;.*ReadOnlyDevice;.*Device;.*RAM;.*ROM;.*Memory;.*Addressable;.*Video;.*Options;.*Main;.*Disk;.*Hexdump"

mainClass in (Compile, run) := Some( "xyz.hyperreal." + name.value.replace('-', '_') + ".Main" )

Expand Down
12 changes: 12 additions & 0 deletions src/test/scala/ExamplesNoCompressed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,16 @@ class ExamplesNoCompressed extends FreeSpec with PropertyChecks with Matchers {
|yes
""".trim.stripMargin
}

"bin2str" in {
Run( "tests/bin2str.hex" ) shouldBe
"""
|zero
|zero
|zero
|zero
|zero
""".trim.stripMargin
}

}
File renamed without changes.
29 changes: 24 additions & 5 deletions tests/bin2str.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@ out( char c ) {

void
print( char* s ) {
for (char* p = s; *p;)
out( *p++ );
while (*s)
out( *s++ );

out( '\n' );
}

int
signum( int n ) {
return n == 0 ? 0 : n < 0 ? -1 : 1;
}

void
prints( int n ) {
static char* signs[] = {
"negative",
"zero",
"positive"
};

print( signs[signum(n) + 1] );
}

char*
bin2str( int n, int radix, char* buf ) {
char digits[] = "0123456789ABCDEF";
Expand All @@ -36,8 +52,7 @@ bin2str( int n, int radix, char* buf ) {
}

int
strcmp( char *s1, char *s2 )
{
strcmp( char *s1, char *s2 ) {
unsigned char c1, c2;

do {
Expand All @@ -55,5 +70,9 @@ void
main() {
char buf[34];

if (bin2str(0x12AB, 16, buf) == 0)
prints( strcmp(bin2str(0, 10, buf), "0") );
prints( strcmp(bin2str(123, 10, buf), "123") );
prints( strcmp(bin2str(0x12AB, 16, buf), "12AB") );
prints( strcmp(bin2str(-123, 10, buf), "-123") );
prints( strcmp(bin2str(-0x12AB, 16, buf), "-12AB") );
}
89 changes: 89 additions & 0 deletions tests/bin2str.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

Hex dump of section '.text':
0x000100c0 37010100 ef00c033 73500000 73500000 7......3sP..sP..
0x000100d0 00000000 00000000 00000000 00000000 ................
0x000100e0 00000000 00000000 00000000 00000000 ................
0x000100f0 00000000 00000000 00000000 00000000 ................
0x00010100 130101fe 233c8100 13040102 93070500 ....#<..........
0x00010110 a307f4fe b7070200 0347f4fe 2380e700 .........G..#...
0x00010120 13000000 03348101 13010102 67800000 .....4......g...
0x00010130 130101fe 233c1100 23388100 13040102 ....#<..#8......
0x00010140 2334a4fe 6f00c001 833784fe 13871700 #4..o....7......
0x00010150 2334e4fe 83c70700 13850700 eff05ffa #4............_.
0x00010160 833784fe 83c70700 e39007fe 1305a000 .7..............
0x00010170 eff01ff9 13000000 83308101 03340101 .........0...4..
0x00010180 13010102 67800000 130101fe 233c8100 ....g.......#<..
0x00010190 13040102 93070500 2326f4fe 8327c4fe ........#&...'..
0x000101a0 9b870700 63800702 8327c4fe 9b870700 ....c....'......
0x000101b0 63d60700 9307f0ff 6f000001 93071000 c.......o.......
0x000101c0 6f008000 93070000 13850700 03348101 o............4..
0x000101d0 13010102 67800000 130101fe 233c1100 ....g.......#<..
0x000101e0 23388100 13040102 93070500 2326f4fe #8..........#&..
0x000101f0 8327c4fe 13850700 eff01ff9 93070500 .'..............
0x00010200 9b871700 1b870700 b7170100 13173700 ..............7.
0x00010210 93878759 b307f700 83b70700 13850700 ...Y............
0x00010220 eff01ff1 13000000 83308101 03340101 .........0...4..
0x00010230 13010102 67800000 130101fc 233c8102 ....g.......#<..
0x00010240 13040104 93070500 13870500 2330c4fc ............#0..
0x00010250 2326f4fc 93070700 2324f4fc b7070100 #&......#$......
0x00010260 03b70753 2338e4fc 13870753 03378700 ...S#8.....S.7..
0x00010270 233ce4fc 93870753 83c70701 2300f4fe #<.....S....#...
0x00010280 833704fc 93871702 2334f4fe 8327c4fc .7......#4...'..
0x00010290 2322f4fe 8327c4fc 9b870700 63d80700 #"...'......c...
0x000102a0 832744fe bb07f040 2322f4fe 833784fe .'D....@#"...7..
0x000102b0 1387f7ff 2334e4fe 23800700 6f000004 ....#4..#...o...
0x000102c0 032744fe 832784fc bb67f702 1b870700 .'D..'...g......
0x000102d0 833784fe 9386f7ff 2334d4fe 930604ff .7......#4......
0x000102e0 3387e600 034707fe 2380e700 032744fe 3....G..#....'D.
0x000102f0 832784fc bb47f702 2322f4fe 032744fe .'...G..#"...'D.
0x00010300 832784fc 1b070700 9b870700 e35af7fa .'...........Z..
0x00010310 832744fe 130704ff b307f700 03c707fe .'D.............
0x00010320 833784fe 2380e700 8327c4fc 9b870700 .7..#....'......
0x00010330 63de0700 833784fe 9387f7ff 2334f4fe c....7......#4..
0x00010340 833784fe 1307d002 2380e700 833784fe .7......#....7..
0x00010350 13850700 03348103 13010104 67800000 .....4......g...
0x00010360 130101fd 23348102 13040103 233ca4fc ....#4......#<..
0x00010370 2338b4fc 833784fd 13871700 233ce4fc #8...7......#<..
0x00010380 83c70700 a307f4fe 833704fd 13871700 .........7......
0x00010390 2338e4fc 83c70700 2307f4fe 8347f4fe #8......#....G..
0x000103a0 93f7f70f 63900702 8347f4fe 1b870700 ....c....G......
0x000103b0 8347e4fe 9b870700 bb07f740 9b870700 .G.........@....
0x000103c0 6f000003 0347f4fe 8347e4fe 1377f70f o....G...G...w..
0x000103d0 93f7f70f e300f7fa 8347f4fe 1b870700 .........G......
0x000103e0 8347e4fe 9b870700 bb07f740 9b870700 .G.........@....
0x000103f0 13850700 03348102 13010103 67800000 .....4......g...
0x00010400 130101fc 233c1102 23388102 13040104 ....#<..#8......
0x00010410 930784fc 13860700 9305a000 13050000 ................
0x00010420 eff09fe1 13070500 b7070100 93858754 ...............T
0x00010430 13050700 eff0dff2 93070500 13850700 ................
0x00010440 eff09fd9 930784fc 13860700 9305a000 ................
0x00010450 1305b007 eff05fde 13070500 b7070100 ......_.........
0x00010460 93850755 13050700 eff09fef 93070500 ...U............
0x00010470 13850700 eff05fd6 930784fc 13860700 ......_.........
0x00010480 93050001 b7170000 1385b72a eff0dfda ...........*....
0x00010490 13070500 b7070100 93858755 13050700 ...........U....
0x000104a0 eff01fec 93070500 13850700 eff0dfd2 ................
0x000104b0 930784fc 13860700 9305a000 130550f8 ..............P.
0x000104c0 eff09fd7 13070500 b7070100 93850756 ...............V
0x000104d0 13050700 eff0dfe8 93070500 13850700 ................
0x000104e0 eff09fcf 930784fc 13860700 93050001 ................
0x000104f0 b7f7ffff 138557d5 eff01fd4 13070500 ......W.........
0x00010500 b7070100 93858756 13050700 eff05fe5 .......V......_.
0x00010510 93070500 13850700 eff01fcc 13000000 ................
0x00010520 83308103 03340103 13010104 67800000 .0...4......g...


Hex dump of section '.rodata':
0x00010530 30313233 34353637 38394142 43444546 0123456789ABCDEF
0x00010540 00000000 00000000 30000000 00000000 ........0.......
0x00010550 31323300 00000000 31324142 00000000 123.....12AB....
0x00010560 2d313233 00000000 2d313241 42000000 -123....-12AB...
0x00010570 6e656761 74697665 00000000 00000000 negative........
0x00010580 7a65726f 00000000 706f7369 74697665 zero....positive
0x00010590 00 .


Hex dump of section '.data':
0x00011598 70050100 00000000 80050100 00000000 p...............
0x000115a8 88050100 00000000 ........

0 comments on commit b8cc11d

Please sign in to comment.