Mercurial > games > semicongine
comparison tests/test_storage.nim @ 1139:114f395b9144
did: finish refactoring and updated all tests accordingly
| author | sam <sam@basx.dev> |
|---|---|
| date | Sat, 08 Jun 2024 14:58:25 +0700 |
| parents | 71315636ba82 |
| children |
comparison
equal
deleted
inserted
replaced
| 1138:02e1d2658ff5 | 1139:114f395b9144 |
|---|---|
| 5 proc testSimple(storage: StorageType) = | 5 proc testSimple(storage: StorageType) = |
| 6 const TEST_VALUE = 42 | 6 const TEST_VALUE = 42 |
| 7 const KEY = "test" | 7 const KEY = "test" |
| 8 | 8 |
| 9 # get default | 9 # get default |
| 10 assert storage.load(KEY, 0) == default(type(TEST_VALUE)) | 10 assert storage.Load(KEY, 0) == default(type(TEST_VALUE)) |
| 11 | 11 |
| 12 # save and load custom | 12 # save and load custom |
| 13 store(storage, KEY, TEST_VALUE) | 13 Store(storage, KEY, TEST_VALUE) |
| 14 assert storage.load(KEY, 0) == TEST_VALUE | 14 assert storage.Load(KEY, 0) == TEST_VALUE |
| 15 | 15 |
| 16 proc stressTest(storage: StorageType) = | 16 proc stressTest(storage: StorageType) = |
| 17 for i in 1 .. 10000: | 17 for i in 1 .. 10000: |
| 18 let key = &"key-{i}" | 18 let key = &"key-{i}" |
| 19 store(storage, key, i) | 19 Store(storage, key, i) |
| 20 assert storage.load(key, 0) == i | 20 assert storage.Load(key, 0) == i |
| 21 | 21 |
| 22 proc main() = | 22 proc main() = |
| 23 SystemStorage.purge() | 23 SystemStorage.Purge() |
| 24 echo "SystemStorage: Testing simple store/load" | 24 echo "SystemStorage: Testing simple store/load" |
| 25 SystemStorage.testSimple() | 25 SystemStorage.testSimple() |
| 26 | 26 |
| 27 UserStorage.purge() | 27 UserStorage.Purge() |
| 28 echo "UserStorage: Testing simple store/load" | 28 echo "UserStorage: Testing simple store/load" |
| 29 UserStorage.testSimple() | 29 UserStorage.testSimple() |
| 30 | 30 |
| 31 echo "Stress test with 10'000 saves/loads" | 31 echo "Stress test with 10'000 saves/loads" |
| 32 SystemStorage.stressTest() | 32 SystemStorage.stressTest() |
| 33 | 33 |
| 34 SystemStorage.purge() | 34 SystemStorage.Purge() |
| 35 UserStorage.purge() | 35 UserStorage.Purge() |
| 36 | 36 |
| 37 | 37 |
| 38 when isMainModule: | 38 when isMainModule: |
| 39 main() | 39 main() |
