diff options
author | Araq <rumpf_a@web.de> | 2012-04-16 16:31:15 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-04-16 16:31:15 +0200 |
commit | 17d67ab82827d10203646066d4d203d1da26a75a (patch) | |
tree | c33e78f4817685c71b2f8d4e5ed41948298067c7 /tests/run | |
parent | a6564092869db9af93b6440006c8b978bff6e17f (diff) | |
download | Nim-17d67ab82827d10203646066d4d203d1da26a75a.tar.gz |
fixes #105
Diffstat (limited to 'tests/run')
-rwxr-xr-x | tests/run/tsortdev.nim | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/run/tsortdev.nim b/tests/run/tsortdev.nim new file mode 100755 index 000000000..d7d42d22c --- /dev/null +++ b/tests/run/tsortdev.nim @@ -0,0 +1,59 @@ +discard """ + output: "done" +""" + +import algorithm, strutils + +proc cmpPlatforms(a, b: string): int = + if a == b: return 0 + var dashes = a.split('-') + var dashes2 = b.split('-') + if dashes[0] == dashes2[0]: + if dashes[1] == dashes2[1]: return system.cmp(a,b) + case dashes[1] + of "x86": + return 1 + of "x86_64": + if dashes2[1] == "x86": return -1 + else: return 1 + of "ppc64": + if dashes2[1] == "x86" or dashes2[1] == "x86_64": return -1 + else: return 1 + else: + return system.cmp(dashes[1], dashes2[1]) + else: + case dashes[0] + of "linux": + return 1 + of "windows": + if dashes2[0] == "linux": return -1 + else: return 1 + of "macosx": + if dashes2[0] == "linux" or dashes2[0] == "windows": return -1 + else: return 1 + else: + if dashes2[0] == "linux" or dashes2[0] == "windows" or + dashes2[0] == "macosx": return -1 + else: + return system.cmp(a, b) + +proc sorted[T](a: openArray[T]): bool = + result = true + for i in 0 .. < a.high: + if cmpPlatforms(a[i], a[i+1]) > 0: + echo "Out of order: ", a[i], " ", a[i+1] + result = false + +proc main() = + var testData = @["netbsd-x86_64", "windows-x86", "linux-x86_64", "linux-x86", + "linux-ppc64", "macosx-x86-1058", "macosx-x86-1068"] + + sort(testData, cmpPlatforms) + + doAssert sorted(testData) + +for i in 0..1_000: + main() + +echo "done" + |