Mercurial > games > semicongine
annotate tests/test_storage.nim @ 1353:93a6d70d845f
fix: make perlin noise 0..1 instead of -1..1
author | sam <sam@basx.dev> |
---|---|
date | Fri, 27 Sep 2024 23:44:37 +0700 |
parents | df3c075e5dea |
children |
rev | line source |
---|---|
1286
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
1 import std/strformat |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
2 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
3 import ../semicongine |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
4 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
5 proc testSimple(storage: StorageType) = |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
6 const TEST_VALUE = 42 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
7 const KEY = "test" |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
8 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
9 # get default |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
10 assert storage.load(KEY, 0) == default(type(TEST_VALUE)) |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
11 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
12 # save and load custom |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
13 store(storage, KEY, TEST_VALUE) |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
14 assert storage.load(KEY, 0) == TEST_VALUE |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
15 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
16 proc stressTest(storage: StorageType) = |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
17 for i in 1 .. 10000: |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
18 let key = &"key-{i}" |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
19 store(storage, key, i) |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
20 assert storage.load(key, 0) == i |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
21 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
22 proc main() = |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
23 SystemStorage.purge() |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
24 echo "SystemStorage: Testing simple store/load" |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
25 SystemStorage.testSimple() |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
26 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
27 UserStorage.purge() |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
28 echo "UserStorage: Testing simple store/load" |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
29 UserStorage.testSimple() |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
30 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
31 echo "Stress test with 10'000 saves/loads" |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
32 SystemStorage.stressTest() |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
33 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
34 SystemStorage.purge() |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
35 UserStorage.purge() |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
36 |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
37 when isMainModule: |
ad9091fde244
add: storage tests, fix something not worth mentioning
sam <sam@basx.dev>
parents:
diff
changeset
|
38 main() |