Skip to content

Commit

Permalink
add quicksort8 test
Browse files Browse the repository at this point in the history
  • Loading branch information
edadma committed Apr 2, 2018
1 parent 2a956dc commit 0647369
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/test/scala/ExamplesNoCompressed.scala
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,16 @@ class ExamplesNoCompressed extends FreeSpec with PropertyChecks with Matchers {
""".trim.stripMargin
}

"quicksort8" in {
Run( "tests/quicksort8.hex" ) shouldBe
"""
|[1, 2, 3, 7, 7, 7, 7, 8, 9, 10]
|[1, 2, 3, 5, 7, 7, 7, 8, 9, 10]
|[1, 2, 3, 4, 5, 7, 7, 8, 9, 10]
|[9, 10]
|[10]
|[]
""".trim.stripMargin
}

}
103 changes: 103 additions & 0 deletions tests/quicksort8.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
void
out( char c ) {
*((char*) 0x20000) = c;
}

//#include <stdio.h>
//#define out( c ) putchar( c )

void
print( char* s ) {
while (*s)
out( *s++ );
}

void
println( char* s ) {
print( s );
out( '\n' );
}

char*
bin2str( char n, int radix, char* buf ) {
char digits[] = "0123456789ABCDEF";
char* p = &buf[33];
char quo = n;

if (n < 0)
quo = -quo;

*p-- = 0;

while (quo >= radix) {
*p-- = digits[(quo%radix)];
quo /= radix;
}

*p = digits[quo];

if (n < 0)
*--p = '-';

return p;
}

void
sort( char a[], int left, int right ) {
if (right > left) {
int i = left;
int j = right;
char tmp = 0;
char p = a[right];

do {
while (a[i] < p)
i++;

while (a[j] > p)
j--;

if (i <= j) {
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
i++;
j--;
}
} while (i <= j);

if (left < j)
sort( a, left, j );

if (i < right)
sort( a, i, right );
}
}

void
run( char array[], int size ) {
sort( array, 0, size - 1 );
print( "[" );

for (int i = 0; i < size; i++) {
char buf[34];
char* s = bin2str( array[i], 10, buf );

print( s );

if (i < size - 1)
print( ", " );
}

println( "]" );
}

void
main() {
run( (char[]){10, 9, 8, 7, 7, 7, 7, 3, 2, 1}, 10 );
run( (char[]){10, 9, 8, 7, 7, 5, 7, 3, 2, 1}, 10 );
run( (char[]){10, 9, 8, 7, 5, 7, 4, 3, 2, 1}, 10 );
run( (char[]){10, 9}, 2 );
run( (char[]){10}, 1 );
run( (char[]){}, 0 );
}
99 changes: 99 additions & 0 deletions tests/quicksort8.hex
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

Hex dump of section '.text':
0x00010080 37010100 ef004048 73500000 00000000 7.....@HsP......
0x00010090 00000000 00000000 00000000 00000000 ................
0x000100a0 00000000 00000000 00000000 00000000 ................
0x000100b0 00000000 00000000 00000000 00000000 ................
0x000100c0 130101fe 233c8100 13040102 93070500 ....#<..........
0x000100d0 a307f4fe b7070200 0347f4fe 2380e700 .........G..#...
0x000100e0 13000000 03348101 13010102 67800000 .....4......g...
0x000100f0 130101fe 233c1100 23388100 13040102 ....#<..#8......
0x00010100 2334a4fe 6f00c001 833784fe 13871700 #4..o....7......
0x00010110 2334e4fe 83c70700 13850700 eff05ffa #4............_.
0x00010120 833784fe 83c70700 e39007fe 13000000 .7..............
0x00010130 83308101 03340101 13010102 67800000 .0...4......g...
0x00010140 130101fe 233c1100 23388100 13040102 ....#<..#8......
0x00010150 2334a4fe 033584fe eff09ff9 1305a000 #4...5..........
0x00010160 eff01ff6 13000000 83308101 03340101 .........0...4..
0x00010170 13010102 67800000 130101fc 233c8102 ....g.......#<..
0x00010180 13040104 93070500 13870500 2330c4fc ............#0..
0x00010190 a307f4fc 93070700 2324f4fc b7070100 ........#$......
0x000101a0 03b7875e 2338e4fc 1387875e 03378700 ...^#8.....^.7..
0x000101b0 233ce4fc 9387875e 83c70701 2300f4fe #<.....^....#...
0x000101c0 833704fc 93871702 2334f4fe 8347f4fc .7......#4...G..
0x000101d0 a303f4fe 833784fe 1387f7ff 2334e4fe .....7......#4..
0x000101e0 23800700 6f000005 834774fe 9b870700 #...o....Gt.....
0x000101f0 13870700 832784fc bb67f702 1b870700 .....'...g......
0x00010200 833784fe 9386f7ff 2334d4fe 930604ff .7......#4......
0x00010210 3387e600 034707fe 2380e700 834774fe 3....G..#....Gt.
0x00010220 1b870700 832784fc bb47f702 9b870700 .....'...G......
0x00010230 a303f4fe 834774fe 1b870700 832784fc .....Gt......'..
0x00010240 9b870700 e352f7fa 834774fe 9b870700 .....R...Gt.....
0x00010250 130704ff b307f700 03c707fe 833784fe .............7..
0x00010260 2380e700 833784fe 13850700 03348103 #....7.......4..
0x00010270 13010104 67800000 130101fd 23341102 ....g.......#4..
0x00010280 23308102 13040103 233ca4fc 93870500 #0......#<......
0x00010290 13070600 232af4fc 93070700 2328f4fc ....#*......#(..
0x000102a0 032704fd 832744fd 1b070700 9b870700 .'...'D.........
0x000102b0 63d2e716 832744fd 2326f4fe 832704fd c....'D.#&...'..
0x000102c0 2324f4fe a30304fe 832704fd 033784fd #$.......'...7..
0x000102d0 b307f700 83c70700 2303f4fe 6f000001 ........#...o...
0x000102e0 8327c4fe 9b871700 2326f4fe 8327c4fe .'......#&...'..
0x000102f0 033784fd b307f700 03c70700 834764fe .7...........Gd.
0x00010300 93f7f70f e36ef7fc 6f000001 832784fe .....n..o....'..
0x00010310 9b87f7ff 2324f4fe 832784fe 033784fd ....#$...'...7..
0x00010320 b307f700 03c70700 834764fe 93f7f70f .........Gd.....
0x00010330 e3eee7fc 0327c4fe 832784fe 1b070700 .....'...'......
0x00010340 9b870700 63c2e706 8327c4fe 033784fd ....c....'...7..
0x00010350 b307f700 83c70700 a303f4fe 832784fe .............'..
0x00010360 033784fd 3307f700 8327c4fe 833684fd .7..3....'...6..
0x00010370 b387f600 03470700 2380e700 832784fe .....G..#....'..
0x00010380 033784fd b307f700 034774fe 2380e700 .7.......Gt.#...
0x00010390 8327c4fe 9b871700 2326f4fe 832784fe .'......#&...'..
0x000103a0 9b87f7ff 2324f4fe 0327c4fe 832784fe ....#$...'...'..
0x000103b0 1b070700 9b870700 e3dae7f2 032744fd .............'D.
0x000103c0 832784fe 1b070700 9b870700 635ef700 .'..........c^..
0x000103d0 032784fe 832744fd 13060700 93850700 .'...'D.........
0x000103e0 033584fd eff05fe9 0327c4fe 832704fd .5...._..'...'..
0x000103f0 1b070700 9b870700 635ef700 032704fd ........c^...'..
0x00010400 8327c4fe 13060700 93850700 033584fd .'...........5..
0x00010410 eff09fe6 13000000 83308102 03340102 .........0...4..
0x00010420 13010103 67800000 130101fa 233c1104 ....g.......#<..
0x00010430 23388104 13040106 2334a4fa 93870500 #8......#4......
0x00010440 2322f4fa 832744fa 9b87f7ff 9b870700 #"...'D.........
0x00010450 13860700 93050000 033584fa eff0dfe1 .........5......
0x00010460 b7070100 13850760 eff09fc8 232604fe .......`....#&..
0x00010470 6f004006 8327c4fe 033784fa b307f700 o.@..'...7......
0x00010480 83c70700 130784fb 13060700 9305a000 ................
0x00010490 13850700 eff05fce 2330a4fe 033504fe ......_.#0...5..
0x000104a0 eff01fc5 832744fa 9b87f7ff 1b870700 .....'D.........
0x000104b0 8327c4fe 9b870700 63d8e700 b7070100 .'......c.......
0x000104c0 13858760 eff0dfc2 8327c4fe 9b871700 ...`.....'......
0x000104d0 2326f4fe 0327c4fe 832744fa 1b070700 #&...'...'D.....
0x000104e0 9b870700 e348f7f8 b7070100 13850761 .....H.........a
0x000104f0 eff01fc5 13000000 83308105 03340105 .........0...4..
0x00010500 13010106 67800000 130101fb 23341104 ....g.......#4..
0x00010510 23308104 13040105 b7070100 03b78761 #0.............a
0x00010520 2338e4fa 93878761 83d78700 231cf4fa #8.....a....#...
0x00010530 930704fb 9305a000 13850700 eff0dfee ................
0x00010540 b7070100 03b78762 2330e4fc 93878762 .......b#0.....b
0x00010550 83d78700 2314f4fc 930704fc 9305a000 ....#...........
0x00010560 13850700 eff05fec b7070100 03b78763 ......_........c
0x00010570 2338e4fc 93878763 83d78700 231cf4fc #8.....c....#...
0x00010580 930704fd 9305a000 13850700 eff0dfe9 ................
0x00010590 9307a000 2300f4fe 93079000 a300f4fe ....#...........
0x000105a0 930704fe 93052000 13850700 eff0dfe7 ...... .........
0x000105b0 9307a000 2304f4fe 930784fe 93051000 ....#...........
0x000105c0 13850700 eff05fe6 93050000 130504ff ......_.........
0x000105d0 eff09fe5 13000000 83308104 03340104 .........0...4..
0x000105e0 13010105 67800000 ....g...


Hex dump of section '.rodata':
0x000105e8 30313233 34353637 38394142 43444546 0123456789ABCDEF
0x000105f8 00000000 00000000 5b000000 00000000 ........[.......
0x00010608 2c200000 00000000 5d000000 00000000 , ......].......
0x00010618 0a090807 07070703 02010000 00000000 ................
0x00010628 0a090807 07050703 02010000 00000000 ................
0x00010638 0a090807 05070403 0201 ..........

0 comments on commit 0647369

Please sign in to comment.