Mercurial > games > semicongine
view tests/test_storage.nim @ 989:3e0116b5d2ed
did: undo complicated background storage API, sync is good enough for now
author | sam <sam@basx.dev> |
---|---|
date | Sun, 07 Apr 2024 21:56:43 +0700 |
parents | 46778940c1d7 |
children | 1705e005cdee |
line wrap: on
line source
import std/os import std/strformat import semicongine proc testSimple(storage: StorageType) = const TEST_VALUE = 42 const KEY = "test" # get default assert load[int](storage, KEY) == default(type(TEST_VALUE)) # save and load custom store(storage, KEY, TEST_VALUE) assert load[int](storage, KEY) == TEST_VALUE proc stressTest(storage: StorageType) = for i in 1 .. 10000: let key = &"key-{i}" store(storage, key, i) assert load[int](storage, key) == i proc main() = SystemStorage.purge() echo "SystemStorage: Testing simple store/load" SystemStorage.testSimple() UserStorage.purge() echo "UserStorage: Testing simple store/load" UserStorage.testSimple() echo "Stress test with 10'000 saves/loads" SystemStorage.stressTest() SystemStorage.purge() UserStorage.purge() when isMainModule: main()