comparison tests/test_storage.nim @ 1286:ad9091fde244

add: storage tests, fix something not worth mentioning
author sam <sam@basx.dev>
date Tue, 30 Jul 2024 14:48:30 +0700
parents
children df3c075e5dea
comparison
equal deleted inserted replaced
1285:6d16003406fb 1286:ad9091fde244
1 import std/strformat
2
3 import ../semicongine
4
5 proc testSimple(storage: StorageType) =
6 const TEST_VALUE = 42
7 const KEY = "test"
8
9 # get default
10 assert storage.load(KEY, 0) == default(type(TEST_VALUE))
11
12 # save and load custom
13 store(storage, KEY, TEST_VALUE)
14 assert storage.load(KEY, 0) == TEST_VALUE
15
16 proc stressTest(storage: StorageType) =
17 for i in 1 .. 10000:
18 let key = &"key-{i}"
19 store(storage, key, i)
20 assert storage.load(key, 0) == i
21
22 proc main() =
23 SystemStorage.purge()
24 echo "SystemStorage: Testing simple store/load"
25 SystemStorage.testSimple()
26
27 UserStorage.purge()
28 echo "UserStorage: Testing simple store/load"
29 UserStorage.testSimple()
30
31 echo "Stress test with 10'000 saves/loads"
32 SystemStorage.stressTest()
33
34 SystemStorage.purge()
35 UserStorage.purge()
36
37
38 when isMainModule:
39 main()