Mercurial > games > semicongine
comparison tests/test_storage.nim @ 990:1705e005cdee
add: enforce adding default value for storage loads
author | sam <sam@basx.dev> |
---|---|
date | Sun, 07 Apr 2024 22:19:39 +0700 |
parents | 3e0116b5d2ed |
children | 71315636ba82 |
comparison
equal
deleted
inserted
replaced
989:3e0116b5d2ed | 990:1705e005cdee |
---|---|
6 proc testSimple(storage: StorageType) = | 6 proc testSimple(storage: StorageType) = |
7 const TEST_VALUE = 42 | 7 const TEST_VALUE = 42 |
8 const KEY = "test" | 8 const KEY = "test" |
9 | 9 |
10 # get default | 10 # get default |
11 assert load[int](storage, KEY) == default(type(TEST_VALUE)) | 11 assert storage.load(KEY, 0) == default(type(TEST_VALUE)) |
12 | 12 |
13 # save and load custom | 13 # save and load custom |
14 store(storage, KEY, TEST_VALUE) | 14 store(storage, KEY, TEST_VALUE) |
15 assert load[int](storage, KEY) == TEST_VALUE | 15 assert storage.load(KEY, 0) == TEST_VALUE |
16 | 16 |
17 proc stressTest(storage: StorageType) = | 17 proc stressTest(storage: StorageType) = |
18 for i in 1 .. 10000: | 18 for i in 1 .. 10000: |
19 let key = &"key-{i}" | 19 let key = &"key-{i}" |
20 store(storage, key, i) | 20 store(storage, key, i) |
21 assert load[int](storage, key) == i | 21 assert storage.load(key, 0) == i |
22 | 22 |
23 proc main() = | 23 proc main() = |
24 SystemStorage.purge() | 24 SystemStorage.purge() |
25 echo "SystemStorage: Testing simple store/load" | 25 echo "SystemStorage: Testing simple store/load" |
26 SystemStorage.testSimple() | 26 SystemStorage.testSimple() |