From bc1db0d6f163e4aba51f27b2a8cefd05476bd5e4 Mon Sep 17 00:00:00 2001 From: flywind <43030857+xflywind@users.noreply.github.com> Date: Sat, 28 Nov 2020 03:47:49 +0800 Subject: move rest of tests to testament (#16140) * move rest of tests to testament * Update tests/stdlib/tsums.nim --- lib/std/editdistance.nim | 41 ----------------------------------------- lib/std/sums.nim | 24 ------------------------ lib/std/with.nim | 20 -------------------- lib/std/wordwrap.nim | 44 -------------------------------------------- 4 files changed, 129 deletions(-) (limited to 'lib/std') diff --git a/lib/std/editdistance.nim b/lib/std/editdistance.nim index f365d4ab2..2c9203d64 100644 --- a/lib/std/editdistance.nim +++ b/lib/std/editdistance.nim @@ -264,44 +264,3 @@ proc editDistanceAscii*(a, b: string): int {.noSideEffect.} = if x > c3: x = c3 row[p] = x result = row[e] - - -when isMainModule: - doAssert editDistance("", "") == 0 - doAssert editDistance("kitten", "sitting") == 3 # from Wikipedia - doAssert editDistance("flaw", "lawn") == 2 # from Wikipedia - - doAssert editDistance("привет", "превет") == 1 - doAssert editDistance("Åge", "Age") == 1 - # editDistance, one string is longer in bytes, but shorter in rune length - # first string: 4 bytes, second: 6 bytes, but only 3 runes - doAssert editDistance("aaaa", "×××") == 4 - - block veryLongStringEditDistanceTest: - const cap = 256 - var - s1 = newStringOfCap(cap) - s2 = newStringOfCap(cap) - while len(s1) < cap: - s1.add 'a' - while len(s2) < cap: - s2.add 'b' - doAssert editDistance(s1, s2) == cap - - block combiningCodePointsEditDistanceTest: - const s = "A\xCC\x8Age" - doAssert editDistance(s, "Age") == 1 - - doAssert editDistanceAscii("", "") == 0 - doAssert editDistanceAscii("kitten", "sitting") == 3 # from Wikipedia - doAssert editDistanceAscii("flaw", "lawn") == 2 # from Wikipedia - - - assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffix") == 0) - assert(editDistance("prefix__hallo_suffix", "prefix__hallo_suffi1") == 1) - assert(editDistance("prefix__hallo_suffix", "prefix__HALLO_suffix") == 5) - assert(editDistance("prefix__hallo_suffix", "prefix__ha_suffix") == 3) - assert(editDistance("prefix__hallo_suffix", "prefix") == 14) - assert(editDistance("prefix__hallo_suffix", "suffix") == 14) - assert(editDistance("prefix__hallo_suffix", "prefix__hao_suffix") == 2) - assert(editDistance("main", "malign") == 2) diff --git a/lib/std/sums.nim b/lib/std/sums.nim index 0f8c5ebfb..cc964b91a 100644 --- a/lib/std/sums.nim +++ b/lib/std/sums.nim @@ -60,27 +60,3 @@ runnableExamples: const data = [1, 2, 3, 4, 5, 6, 7, 8, 9] doAssert sumKbn(data) == 45 doAssert sumPairs(data) == 45 - - -when isMainModule: - from math import pow - - var epsilon = 1.0 - while 1.0 + epsilon != 1.0: - epsilon /= 2.0 - let data = @[1.0, epsilon, -epsilon] - assert sumKbn(data) == 1.0 - assert sumPairs(data) != 1.0 # known to fail - assert (1.0 + epsilon) - epsilon != 1.0 - - var tc1: seq[float] - for n in 1 .. 1000: - tc1.add 1.0 / n.float - assert sumKbn(tc1) == 7.485470860550345 - assert sumPairs(tc1) == 7.485470860550345 - - var tc2: seq[float] - for n in 1 .. 1000: - tc2.add pow(-1.0, n.float) / n.float - assert sumKbn(tc2) == -0.6926474305598203 - assert sumPairs(tc2) == -0.6926474305598204 diff --git a/lib/std/with.nim b/lib/std/with.nim index ea26065a1..e6784478c 100644 --- a/lib/std/with.nim +++ b/lib/std/with.nim @@ -36,23 +36,3 @@ macro with*(arg: typed; calls: varargs[untyped]): untyped = result = newNimNode(nnkStmtList, arg) underscoredCalls(result, calls, arg) - -when isMainModule: - type - Foo = object - col, pos: string - name: string - - proc setColor(f: var Foo; r, g, b: int) = f.col = $(r, g, b) - proc setPosition(f: var Foo; x, y: float) = f.pos = $(x, y) - - var f: Foo - with(f, setColor(2, 3, 4), setPosition(0.0, 1.0)) - echo f - - f = Foo() - with f: - col = $(2, 3, 4) - pos = $(0.0, 1.0) - _.name = "bar" - echo f diff --git a/lib/std/wordwrap.nim b/lib/std/wordwrap.nim index 27df229bf..7dcfc7f59 100644 --- a/lib/std/wordwrap.nim +++ b/lib/std/wordwrap.nim @@ -72,47 +72,3 @@ proc wrapWords*(s: string, maxLineWidth = 80, for k in i..