Skip to content

Commit bff8ab8

Browse files
committed
feat(core): initial code commit
1 parent 536c615 commit bff8ab8

File tree

9 files changed

+496
-0
lines changed

9 files changed

+496
-0
lines changed

.github/workflows/branches.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Branches
5+
6+
on:
7+
push:
8+
branches-ignore:
9+
- master
10+
11+
jobs:
12+
build:
13+
name: Build
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version:
19+
- 12.x
20+
- 14.x
21+
- 15.x
22+
steps:
23+
- uses: actions/checkout@v2
24+
- name: Use Node.js ${{ matrix.node-version }}
25+
uses: actions/setup-node@v1
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
- run: yarn
29+
- run: yarn build
30+
- run: yarn test
31+
env:
32+
CI: true

.github/workflows/master.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Master
5+
6+
on:
7+
push:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
name: Build
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
node-version:
18+
- 12.x
19+
- 14.x
20+
- 15.x
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v1
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
- run: yarn
28+
- run: yarn build
29+
- run: yarn test
30+
env:
31+
CI: true
32+
33+
release:
34+
name: Release
35+
runs-on: ubuntu-latest
36+
needs: build
37+
steps:
38+
- name: Checkout
39+
uses: actions/checkout@v1
40+
- name: Setup Node.js
41+
uses: actions/setup-node@v1
42+
with:
43+
node-version: 14
44+
- run: yarn
45+
- run: yarn build
46+
- run: yarn test
47+
env:
48+
CI: true
49+
- name: Coveralls
50+
uses: coverallsapp/github-action@master
51+
with:
52+
github-token: ${{ secrets.GITHUB_TOKEN }}
53+
- name: Release
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
57+
run: npx semantic-release

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
coverage
4+
yarn.lock

jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
coverageReporters: [ 'lcov', 'text', 'html' ],
5+
};

lib/index.test.ts

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import { arrayEqual, rotatedArrayEqual, RotatedArraySet } from './index'
2+
3+
4+
describe( "arrayEqual", ( ) =>
5+
{
6+
it( "should handle diffently sized arays", ( ) =>
7+
{
8+
expect( arrayEqual( [ 'a', 'c' ], [ 'b' ] ) ).toBe( false );
9+
} );
10+
11+
it( "should handle two empty arrays", ( ) =>
12+
{
13+
expect( arrayEqual( [ ], [ ] ) ).toBe( true );
14+
} );
15+
16+
it( "should same-size different arrays", ( ) =>
17+
{
18+
expect( arrayEqual( [ 'a', 'b' ], [ 'a', 'c' ] ) ).toBe( false );
19+
} );
20+
21+
it( "should same-size equal arrays", ( ) =>
22+
{
23+
expect( arrayEqual( [ 'a', 'b' ], [ 'a', 'b' ] ) ).toBe( true );
24+
} );
25+
} );
26+
27+
describe( "rotatedArrayEqual", ( ) =>
28+
{
29+
it( "should handle diffently sized arays", ( ) =>
30+
{
31+
expect( rotatedArrayEqual( [ 'a', 'c' ], [ 'b' ] ) ).toBe( false );
32+
} );
33+
34+
it( "should handle two empty arrays", ( ) =>
35+
{
36+
expect( rotatedArrayEqual( [ ], [ ] ) ).toBe( true );
37+
} );
38+
39+
it( "should same-size different arrays (begins with same entry)", ( ) =>
40+
{
41+
expect( rotatedArrayEqual( [ 'a', 'b' ], [ 'a', 'c' ] ) )
42+
.toBe( false );
43+
} );
44+
45+
it( "should same-size different arrays", ( ) =>
46+
{
47+
expect( rotatedArrayEqual( [ 'a', 'b' ], [ 'x', 'c' ] ) )
48+
.toBe( false );
49+
} );
50+
51+
it( "should same-size equal unrotated arrays", ( ) =>
52+
{
53+
expect( rotatedArrayEqual( [ 'a', 'b', 'c' ], [ 'a', 'b', 'c' ] ) )
54+
.toBe( true );
55+
} );
56+
57+
it( "should same-size equal rotated arrays", ( ) =>
58+
{
59+
expect( rotatedArrayEqual( [ 'a', 'b', 'c' ], [ 'c', 'a', 'b' ] ) )
60+
.toBe( true );
61+
} );
62+
} );
63+
64+
describe( "RotatedArraySet", ( ) =>
65+
{
66+
it( "should handle rotated arrays incl empty strings", ( ) =>
67+
{
68+
const arraySet = new RotatedArraySet< string >( );
69+
70+
arraySet.add( [ 'a', '', 'b' ] );
71+
arraySet.add( [ '', '' ] );
72+
arraySet.add( [ ] );
73+
arraySet.add( [ '', '' ] );
74+
arraySet.add( [ ] );
75+
arraySet.add( [ 'b', 'a', '' ] );
76+
77+
expect( arraySet.values( ) ).toStrictEqual( [
78+
[ 'a', '', 'b' ],
79+
[ '', '' ],
80+
[ ],
81+
] );
82+
} );
83+
84+
it( "should handle rotated arrays", ( ) =>
85+
{
86+
const arraySet = new RotatedArraySet< string >( );
87+
88+
arraySet.add( [ 'a', 'b' ] );
89+
arraySet.add( [ 'a', 'b', 'c' ] );
90+
arraySet.add( [ 'b', 'c', 'a' ] );
91+
arraySet.add( [ 'b', 'a' ] );
92+
93+
expect( arraySet.values( ) ).toStrictEqual( [
94+
[ 'a', 'b' ],
95+
[ 'a', 'b', 'c' ],
96+
] );
97+
} );
98+
99+
it( "should handle has()", ( ) =>
100+
{
101+
const arraySet = new RotatedArraySet< string >( );
102+
103+
expect( arraySet.has( [ 'a', 'b' ] ) ).toBe( false );
104+
arraySet.add( [ 'a', 'b' ] );
105+
expect( arraySet.has( [ 'a', 'b' ] ) ).toBe( true );
106+
107+
expect( arraySet.has( [ 'a', 'b', 'c' ] ) ).toBe( false );
108+
arraySet.add( [ 'a', 'b', 'c' ] );
109+
expect( arraySet.has( [ 'a', 'b', 'c' ] ) ).toBe( true );
110+
111+
arraySet.add( [ 'b', 'c', 'a' ] );
112+
expect( arraySet.has( [ 'a', 'b', 'c' ] ) ).toBe( true );
113+
114+
arraySet.add( [ 'b', 'a' ] );
115+
expect( arraySet.has( [ 'a', 'b' ] ) ).toBe( true );
116+
117+
expect( arraySet.has( [ 'foo', 'bar' ] ) ).toBe( false );
118+
119+
expect( arraySet.values( ) ).toStrictEqual( [
120+
[ 'a', 'b' ],
121+
[ 'a', 'b', 'c' ],
122+
] );
123+
} );
124+
125+
it( "should handle rotated arrays of long strings", ( ) =>
126+
{
127+
const arraySet = new RotatedArraySet< string >( );
128+
129+
arraySet.add( [ 'a long string', 'another long' ] );
130+
arraySet.add( [ 'a', 'very long', 'set of strings' ] );
131+
arraySet.add( [ 'very long', 'set of strings', 'a' ] );
132+
arraySet.add( [ 'another long', 'a long string' ] );
133+
134+
expect( arraySet.values( ) ).toStrictEqual( [
135+
[ 'a long string', 'another long' ],
136+
[ 'a', 'very long', 'set of strings' ],
137+
] );
138+
} );
139+
140+
it( "should handle delete arrays", ( ) =>
141+
{
142+
const arraySet = new RotatedArraySet< string >( );
143+
144+
arraySet.add( [ 'a', 'b' ] );
145+
arraySet.add( [ 'a', 'b', 'c' ] );
146+
arraySet.add( [ 'b', 'c', 'a' ] );
147+
arraySet.add( [ 'b', 'a' ] );
148+
expect( arraySet.delete( [ 'c', 'a', 'b' ] ) ).toBe( true );
149+
expect( arraySet.delete( [ 'foo', 'bar' ] ) ).toBe( false );
150+
151+
expect( arraySet.values( ) ).toStrictEqual( [
152+
[ 'a', 'b' ],
153+
] );
154+
} );
155+
} );

0 commit comments

Comments
 (0)