Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer committed Mar 7, 2024
1 parent 1d66ff2 commit 44d14c0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .run/spice.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="spice" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -O0 -d ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<configuration default="false" name="spice" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="run -O3 -d ../../media/test-project/test.spice" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Spice" TARGET_NAME="spice" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Spice" RUN_TARGET_NAME="spice">
<envs>
<env name="LLVM_BUILD_INCLUDE_DIR" value="D:/LLVM/build-release/include" />
<env name="LLVM_INCLUDE_DIR" value="D:/LLVM/llvm/include" />
Expand Down
39 changes: 28 additions & 11 deletions media/test-project/test.spice
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
import "std/data/unordered-map";
import "std/time/timer";

f<int> main() {
UnorderedMap<int, string> map;
Timer timer = Timer();
timer.start();

UnorderedMap<int, string> map = UnorderedMap<int, string>(3l);
assert map.getSize() == 0;
assert map.isEmpty();
map.upsert(1, "one");
map.upsert(2, "two");
map.upsert(3, "three");
map.upsert(4, "four");
assert map.getSize() == 4;
assert !map.isEmpty();
assert map.contains(1);
assert map.contains(2);
assert map.contains(3);
assert !map.contains(4);
assert map.getSize() == 3;
for int i = 1; i <= 3; i++ {
printf("%s\n", map.get(i));
}
const Result<string> item4 = map.getSafe(4);
assert item4.isErr();
assert map.contains(4);
assert !map.contains(5);
assert map.get(1) == "one";
assert map.get(2) == "two";
assert map.get(3) == "three";
assert map.get(4) == "four";
const Result<string> item5 = map.getSafe(5);
assert item5.isErr();
map.remove(2);
assert !map.contains(2);
assert map.getSize() == 2;
assert map.getSize() == 3;
map.clear();
assert map.getSize() == 0;
assert map.isEmpty();
map.upsert(1, "one");
map.upsert(1, "one new");
assert map.getSize() == 1;
assert map.get(1) == "one new";
map.remove(1);
assert map.isEmpty();


printf("All assertions passed!\n");
timer.stop();
printf("All assertions passed in %d microseconds!\n", timer.getDurationInMicros());
}

/*import "bootstrap/util/block-allocator";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
All assertions passed!
38 changes: 38 additions & 0 deletions test/test-files/std/data/unordered-map-normal-usecase/source.spice
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import "std/data/unordered-map";

f<int> main() {
UnorderedMap<int, string> map = UnorderedMap<int, string>(3l);
assert map.getSize() == 0;
assert map.isEmpty();
map.upsert(1, "one");
map.upsert(2, "two");
map.upsert(3, "three");
map.upsert(4, "four");
assert map.getSize() == 4;
assert !map.isEmpty();
assert map.contains(1);
assert map.contains(2);
assert map.contains(3);
assert map.contains(4);
assert !map.contains(5);
assert map.get(1) == "one";
assert map.get(2) == "two";
assert map.get(3) == "three";
assert map.get(4) == "four";
const Result<string> item5 = map.getSafe(5);
assert item5.isErr();
map.remove(2);
assert !map.contains(2);
assert map.getSize() == 3;
map.clear();
assert map.getSize() == 0;
assert map.isEmpty();
map.upsert(1, "one");
map.upsert(1, "one new");
assert map.getSize() == 1;
assert map.get(1) == "one new";
map.remove(1);
assert map.isEmpty();

printf("All assertions passed!\n");
}

0 comments on commit 44d14c0

Please sign in to comment.