Mercurial > games > semicongine
annotate tests/test_storage.nim @ 1114:75e109bb62ba
add: assignment operator, normal 2D vector
author | sam <sam@basx.dev> |
---|---|
date | Mon, 15 Apr 2024 14:36:19 +0700 |
parents | 1205e7757732 |
children | 71315636ba82 |
rev | line source |
---|---|
1095 | 1 import std/os |
1096
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
2 import std/strformat |
1095 | 3 |
4 import semicongine | |
5 | |
6 proc testSimple(storage: StorageType) = | |
7 const TEST_VALUE = 42 | |
8 const KEY = "test" | |
9 | |
10 # get default | |
1099
1205e7757732
add: enforce adding default value for storage loads
sam <sam@basx.dev>
parents:
1098
diff
changeset
|
11 assert storage.load(KEY, 0) == default(type(TEST_VALUE)) |
1095 | 12 |
13 # save and load custom | |
1098
45cf94a6535c
did: undo complicated background storage API, sync is good enough for now
sam <sam@basx.dev>
parents:
1097
diff
changeset
|
14 store(storage, KEY, TEST_VALUE) |
1099
1205e7757732
add: enforce adding default value for storage loads
sam <sam@basx.dev>
parents:
1098
diff
changeset
|
15 assert storage.load(KEY, 0) == TEST_VALUE |
1096
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
16 |
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
17 proc stressTest(storage: StorageType) = |
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
18 for i in 1 .. 10000: |
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
19 let key = &"key-{i}" |
1098
45cf94a6535c
did: undo complicated background storage API, sync is good enough for now
sam <sam@basx.dev>
parents:
1097
diff
changeset
|
20 store(storage, key, i) |
1099
1205e7757732
add: enforce adding default value for storage loads
sam <sam@basx.dev>
parents:
1098
diff
changeset
|
21 assert storage.load(key, 0) == i |
1096
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
22 |
1095 | 23 proc main() = |
1096
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
24 SystemStorage.purge() |
1095 | 25 echo "SystemStorage: Testing simple store/load" |
26 SystemStorage.testSimple() | |
27 | |
28 UserStorage.purge() | |
29 echo "UserStorage: Testing simple store/load" | |
30 UserStorage.testSimple() | |
1096
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
31 |
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
32 echo "Stress test with 10'000 saves/loads" |
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
33 SystemStorage.stressTest() |
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
34 |
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
35 SystemStorage.purge() |
1095 | 36 UserStorage.purge() |
37 | |
1096
9809bd9e2cdb
add: tests and did some simplification of code
sam <sam@basx.dev>
parents:
1095
diff
changeset
|
38 |
1095 | 39 when isMainModule: |
1098
45cf94a6535c
did: undo complicated background storage API, sync is good enough for now
sam <sam@basx.dev>
parents:
1097
diff
changeset
|
40 main() |