Mercurial > games > semicongine
comparison old_tests/test_storage.nim @ 1203:6360c8d17ce0 compiletime-tests
did: preprations to add rendering tests
author | sam <sam@basx.dev> |
---|---|
date | Mon, 15 Jul 2024 20:06:42 +0700 |
parents | tests/test_storage.nim@114f395b9144 |
children |
comparison
equal
deleted
inserted
replaced
1202:a8864fe6fe6e | 1203:6360c8d17ce0 |
---|---|
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() |