Skip to content

Commit

Permalink
add unit test framework
Browse files Browse the repository at this point in the history
  • Loading branch information
noahm committed Apr 1, 2024
1 parent 3496de4 commit a891600
Show file tree
Hide file tree
Showing 3 changed files with 624 additions and 6 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"lint": "biome check sdk ui",
"lint:ci": "biome ci sdk ui",
"preview": "vite preview",
"test": "vitest",
"typecheck": "tsc"
},
"keywords": [
Expand All @@ -32,7 +33,8 @@
"@types/w3c-web-hid": "1.0.6",
"@vitejs/plugin-react": "^4.2.1",
"typescript": "^5.4.3",
"vite": "^5.2.6"
"vite": "^5.2.6",
"vitest": "^1.4.0"
},
"packageManager": "yarn@4.1.1"
}
73 changes: 73 additions & 0 deletions sdk/commands/enabled-sensors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { sbytes, sview } from "@nmann/struct-buffer";
import { expect, test } from "vitest";
import { EnabledSensors } from "./enabled-sensors";

const enabledSensors = new EnabledSensors();

const decodedData = [
{
down: true,
left: true,
right: true,
up: true,
},
{
down: false,
left: false,
right: false,
up: false,
},
{
down: true,
left: true,
right: true,
up: true,
},
{
down: false,
left: false,
right: false,
up: false,
},
{
down: true,
left: true,
right: true,
up: true,
},
{
down: true,
left: true,
right: true,
up: true,
},
{
down: true,
left: true,
right: true,
up: true,
},
{
down: false,
left: false,
right: false,
up: false,
},
{
down: false,
left: false,
right: false,
up: false,
},
];

const encodedData = "0f 0f ff 0f 00";

test("decode", () => {
expect(enabledSensors.decode(sbytes(encodedData))).toEqual(decodedData);
});

test("encode", () => {
// this currently fails for reasons I don't quite understand. probably endianness or something
expect(sview(enabledSensors.encode(decodedData, false))).toEqual(encodedData);
});
Loading

0 comments on commit a891600

Please sign in to comment.