Mercurial > games > semicongine
comparison tests/test_storage.nim @ 1099:1205e7757732
add: enforce adding default value for storage loads
author | sam <sam@basx.dev> |
---|---|
date | Sun, 07 Apr 2024 22:19:39 +0700 |
parents | 45cf94a6535c |
children | 71315636ba82 |
comparison
equal
deleted
inserted
replaced
1098:45cf94a6535c | 1099:1205e7757732 |
---|---|
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() |