make tests green
This commit is contained in:
parent
bbb0fd4eb7
commit
d8fde9daba
6 changed files with 17 additions and 17 deletions
|
|
@ -12,11 +12,11 @@ const
|
||||||
|
|
||||||
var clientCount = 0
|
var clientCount = 0
|
||||||
|
|
||||||
proc sendMessages(client: TAsyncFD) {.async.} =
|
proc sendMessages(client: AsyncFD) {.async.} =
|
||||||
for i in 0 .. <messagesToSend:
|
for i in 0 .. <messagesToSend:
|
||||||
await send(client, "Message " & $i & "\c\L")
|
await send(client, "Message " & $i & "\c\L")
|
||||||
|
|
||||||
proc launchSwarm(port: TPort) {.async.} =
|
proc launchSwarm(port: Port) {.async.} =
|
||||||
for i in 0 .. <swarmSize:
|
for i in 0 .. <swarmSize:
|
||||||
var sock = newAsyncNativeSocket()
|
var sock = newAsyncNativeSocket()
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ proc launchSwarm(port: TPort) {.async.} =
|
||||||
await sendMessages(sock)
|
await sendMessages(sock)
|
||||||
closeSocket(sock)
|
closeSocket(sock)
|
||||||
|
|
||||||
proc readMessages(client: TAsyncFD) {.async.} =
|
proc readMessages(client: AsyncFD) {.async.} =
|
||||||
while true:
|
while true:
|
||||||
var line = await recvLine(client)
|
var line = await recvLine(client)
|
||||||
if line == "":
|
if line == "":
|
||||||
|
|
@ -37,7 +37,7 @@ proc readMessages(client: TAsyncFD) {.async.} =
|
||||||
else:
|
else:
|
||||||
doAssert false
|
doAssert false
|
||||||
|
|
||||||
proc createServer(port: TPort) {.async.} =
|
proc createServer(port: Port) {.async.} =
|
||||||
var server = newAsyncNativeSocket()
|
var server = newAsyncNativeSocket()
|
||||||
block:
|
block:
|
||||||
var name: Sockaddr_in
|
var name: Sockaddr_in
|
||||||
|
|
@ -55,8 +55,8 @@ proc createServer(port: TPort) {.async.} =
|
||||||
while true:
|
while true:
|
||||||
asyncCheck readMessages(await accept(server))
|
asyncCheck readMessages(await accept(server))
|
||||||
|
|
||||||
asyncCheck createServer(TPort(10335))
|
asyncCheck createServer(Port(10335))
|
||||||
asyncCheck launchSwarm(TPort(10335))
|
asyncCheck launchSwarm(Port(10335))
|
||||||
while true:
|
while true:
|
||||||
poll()
|
poll()
|
||||||
if clientCount == swarmSize: break
|
if clientCount == swarmSize: break
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ discard """
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import tables
|
import tables
|
||||||
from hashes import THash
|
from hashes import Hash
|
||||||
|
|
||||||
# Test with int
|
# Test with int
|
||||||
block:
|
block:
|
||||||
|
|
@ -66,7 +66,7 @@ block:
|
||||||
# The same test with a custom hash(s: string) does
|
# The same test with a custom hash(s: string) does
|
||||||
# work though.
|
# work though.
|
||||||
block:
|
block:
|
||||||
proc hash(x: int): THash {.inline.} =
|
proc hash(x: int): Hash {.inline.} =
|
||||||
echo "overloaded hash"
|
echo "overloaded hash"
|
||||||
result = x
|
result = x
|
||||||
var t = initTable[int, int]()
|
var t = initTable[int, int]()
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ semiProblem()
|
||||||
# bug #844
|
# bug #844
|
||||||
|
|
||||||
import json
|
import json
|
||||||
proc parseResponse(): PJsonNode =
|
proc parseResponse(): JsonNode =
|
||||||
result = % { "key1": % { "key2": % "value" } }
|
result = % { "key1": % { "key2": % "value" } }
|
||||||
for key, val in result["key1"]:
|
for key, val in result["key1"]:
|
||||||
var excMsg = key & "("
|
var excMsg = key & "("
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,11 @@ proc mustRehash(length, counter: int): bool {.inline.} =
|
||||||
assert(length > counter)
|
assert(length > counter)
|
||||||
result = (length * 2 < counter * 3) or (length - counter < 4)
|
result = (length * 2 < counter * 3) or (length - counter < 4)
|
||||||
|
|
||||||
proc nextTry(h, maxHash: THash): THash {.inline.} =
|
proc nextTry(h, maxHash: Hash): Hash {.inline.} =
|
||||||
result = ((5 * h) + 1) and maxHash
|
result = ((5 * h) + 1) and maxHash
|
||||||
|
|
||||||
template rawGetImpl() =
|
template rawGetImpl() =
|
||||||
var h: THash = hash(key) and high(t.data) # start with real hash value
|
var h: Hash = hash(key) and high(t.data) # start with real hash value
|
||||||
while t.data[h].slot != seEmpty:
|
while t.data[h].slot != seEmpty:
|
||||||
if t.data[h].key == key and t.data[h].slot == seFilled:
|
if t.data[h].key == key and t.data[h].slot == seFilled:
|
||||||
return h
|
return h
|
||||||
|
|
@ -52,7 +52,7 @@ template rawGetImpl() =
|
||||||
result = -1
|
result = -1
|
||||||
|
|
||||||
template rawInsertImpl() =
|
template rawInsertImpl() =
|
||||||
var h: THash = hash(key) and high(data)
|
var h: Hash = hash(key) and high(data)
|
||||||
while data[h].slot == seFilled:
|
while data[h].slot == seFilled:
|
||||||
h = nextTry(h, high(data))
|
h = nextTry(h, high(data))
|
||||||
data[h].key = key
|
data[h].key = key
|
||||||
|
|
@ -162,7 +162,7 @@ iterator values*[A](t: TCountTable[A]): int =
|
||||||
if t.data[h].val != 0: yield t.data[h].val
|
if t.data[h].val != 0: yield t.data[h].val
|
||||||
|
|
||||||
proc RawGet[A](t: TCountTable[A], key: A): int =
|
proc RawGet[A](t: TCountTable[A], key: A): int =
|
||||||
var h: THash = hash(key) and high(t.data) # start with real hash value
|
var h: Hash = hash(key) and high(t.data) # start with real hash value
|
||||||
while t.data[h].val != 0:
|
while t.data[h].val != 0:
|
||||||
if t.data[h].key == key: return h
|
if t.data[h].key == key: return h
|
||||||
h = nextTry(h, high(t.data))
|
h = nextTry(h, high(t.data))
|
||||||
|
|
@ -181,7 +181,7 @@ proc hasKey*[A](t: TCountTable[A], key: A): bool =
|
||||||
|
|
||||||
proc rawInsert[A](t: TCountTable[A], data: var seq[tuple[key: A, val: int]],
|
proc rawInsert[A](t: TCountTable[A], data: var seq[tuple[key: A, val: int]],
|
||||||
key: A, val: int) =
|
key: A, val: int) =
|
||||||
var h: THash = hash(key) and high(data)
|
var h: Hash = hash(key) and high(data)
|
||||||
while data[h].val != 0: h = nextTry(h, high(data))
|
while data[h].val != 0: h = nextTry(h, high(data))
|
||||||
data[h].key = key
|
data[h].key = key
|
||||||
data[h].val = val
|
data[h].val = val
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ true'''
|
||||||
|
|
||||||
import pegs
|
import pegs
|
||||||
|
|
||||||
template optPeg{peg(pattern)}(pattern: string{lit}): TPeg =
|
template optPeg{peg(pattern)}(pattern: string{lit}): Peg =
|
||||||
var gl {.global, gensym.} = peg(pattern)
|
var gl {.global, gensym.} = peg(pattern)
|
||||||
gl
|
gl
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ proc works() =
|
||||||
sort(f, system.cmp[int])
|
sort(f, system.cmp[int])
|
||||||
outp(f)
|
outp(f)
|
||||||
|
|
||||||
proc weird(json_params: TTable) =
|
proc weird(json_params: Table) =
|
||||||
var f = @[3, 2, 1]
|
var f = @[3, 2, 1]
|
||||||
# The following line doesn't compile: type mismatch. Why?
|
# The following line doesn't compile: type mismatch. Why?
|
||||||
sort(f, system.cmp[int])
|
sort(f, system.cmp[int])
|
||||||
|
|
@ -29,4 +29,4 @@ when isMainModule:
|
||||||
sort(t, system.cmp[int])
|
sort(t, system.cmp[int])
|
||||||
outp(t)
|
outp(t)
|
||||||
works()
|
works()
|
||||||
weird(initTable[string, TJsonNode]())
|
weird(initTable[string, JsonNode]())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue