Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Jan 11, 2024
0 parents commit 3dc85c8
Show file tree
Hide file tree
Showing 11 changed files with 5,150 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
overrides: [
{
env: {
node: true,
},
files: ['.eslintrc.{js,cjs}'],
parserOptions: {
sourceType: 'script',
},
},
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {},
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"tabWidth": 2,
"useTabs": false
}
37 changes: 37 additions & 0 deletions __tests__/instruction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { FULL_MASK, Instruction } from '../src/common';
import { InstructionCodec } from '../src/instruction';

describe('InstructionCodec works', () => {
describe("Parsing works", () => {
test('parses a Partition instruction correctly', () => {
const codec = new InstructionCodec();
const result = codec.deserialize('PARTITION(5,1)');
expect(result).toEqual({ kind: 'Partition', pivot: 5, ownPart: 1 });
});

test('parses an Interlace instruction correctly', () => {
const codec = new InstructionCodec();
const result = codec.deserialize(`INTERLACE(${FULL_MASK})`);
expect(result).toEqual({ kind: 'Interlace', ownMask: FULL_MASK });
});

test('throws an error for unknown instruction kind', () => {
const codec = new InstructionCodec();
expect(() => codec.deserialize('UNKNOWN(1,2)')).toThrow('Unknown instruction');
});
});

describe("Serialization works", () => {
test('serializes a Partition instruction correctly', () => {
const codec = new InstructionCodec();
const instruction: Instruction = { kind: 'Partition', pivot: 5, ownPart: 1 };
expect(codec.serialize(instruction)).toEqual('PARTITION(5,1)');
});

test('serializes an Interlace instruction correctly', () => {
const codec = new InstructionCodec();
const instruction: Instruction = { kind: 'Interlace', ownMask: FULL_MASK };
expect(codec.serialize(instruction)).toEqual(`INTERLACE(${FULL_MASK})`);
});
});
});
5 changes: 5 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};

Loading

0 comments on commit 3dc85c8

Please sign in to comment.