-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(#44): Support Arbitrary-Width Shifts, Add More Test Cases, Ad…
…d Readme
- Loading branch information
1 parent
e524183
commit 983d572
Showing
5 changed files
with
145 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,54 @@ | ||
import { Bits } from '../types' | ||
import circularShiftLeft from './circular-shift-left' | ||
|
||
test('CSHIFTL', () => { | ||
const bits1: Bits = [1, 0, 0, 0, 1, 1, 0, 1] | ||
const expected1: Bits = [0, 0, 0, 1, 1, 0, 1, 1] | ||
expect(circularShiftLeft(bits1)).toEqual(expected1) | ||
|
||
const bits2: Bits = [0, 0, 0, 1, 1, 1, 1, 1] | ||
const expected2: Bits = [0, 0, 1, 1, 1, 1, 1, 0] | ||
expect(circularShiftLeft(bits2)).toEqual(expected2) | ||
test('circularShiftLeft with amount 1', () => { | ||
const testCases: Array<[Bits, Bits]> = [ | ||
[ | ||
[1, 0, 0, 0, 1, 1, 0, 1], | ||
[0, 0, 0, 1, 1, 0, 1, 1], | ||
], | ||
[ | ||
[0, 0, 0, 1, 1, 1, 1, 1], | ||
[0, 0, 1, 1, 1, 1, 1, 0], | ||
], | ||
] | ||
|
||
for (const [input, expectedResult] of testCases) | ||
expect(circularShiftLeft(input, 1)).toEqual(expectedResult) | ||
}) | ||
|
||
test('circularShiftLeft with amount 2', () => { | ||
const testCases: Array<[Bits, Bits]> = [ | ||
[ | ||
[1, 0, 0, 0, 1, 1, 0, 1], | ||
[0, 0, 1, 1, 0, 1, 1, 0], | ||
], | ||
[ | ||
[0, 0, 0, 1, 1, 1, 1, 1], | ||
[0, 1, 1, 1, 1, 1, 0, 0], | ||
], | ||
] | ||
|
||
for (const [input, expectedResult] of testCases) | ||
expect(circularShiftLeft(input, 2)).toEqual(expectedResult) | ||
}) | ||
|
||
test('circularShiftLeft with amount 3', () => { | ||
const testCases: Array<[Bits, Bits]> = [ | ||
[ | ||
[1, 0, 0, 0, 1, 1, 0, 1], | ||
[0, 1, 1, 0, 1, 1, 0, 0], | ||
], | ||
[ | ||
[0, 0, 0, 1, 1, 1, 1, 1], | ||
[1, 1, 1, 1, 1, 0, 0, 0], | ||
], | ||
] | ||
|
||
for (const [input, expectedResult] of testCases) | ||
expect(circularShiftLeft(input, 3)).toEqual(expectedResult) | ||
}) | ||
|
||
test('circularShiftLeft throws when amount too large', () => { | ||
expect(() => circularShiftLeft([0, 1], 3)).toThrow() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,54 @@ | ||
import { Bits } from '../types' | ||
import circularShiftRight from './circular-shift-right' | ||
|
||
test('CSHIFTR', () => { | ||
const bits1: Bits = [1, 0, 0, 0, 1, 1, 0, 1] | ||
const expected1: Bits = [1, 1, 0, 0, 0, 1, 1, 0] | ||
expect(circularShiftRight(bits1)).toEqual(expected1) | ||
|
||
const bits2: Bits = [0, 0, 0, 1, 1, 1, 1, 1] | ||
const expected2: Bits = [1, 0, 0, 0, 1, 1, 1, 1] | ||
expect(circularShiftRight(bits2)).toEqual(expected2) | ||
test('circularShiftRight with amount 1', () => { | ||
const testCases: Array<[Bits, Bits]> = [ | ||
[ | ||
[1, 0, 0, 0, 1, 1, 0, 1], | ||
[1, 1, 0, 0, 0, 1, 1, 0], | ||
], | ||
[ | ||
[0, 0, 0, 1, 1, 1, 1, 1], | ||
[1, 0, 0, 0, 1, 1, 1, 1], | ||
], | ||
] | ||
|
||
for (const [input, expectedResult] of testCases) | ||
expect(circularShiftRight(input, 1)).toEqual(expectedResult) | ||
}) | ||
|
||
test('circularShiftRight with amount 2', () => { | ||
const testCases: Array<[Bits, Bits]> = [ | ||
[ | ||
[1, 0, 0, 0, 1, 1, 0, 1], | ||
[0, 1, 1, 0, 0, 0, 1, 1], | ||
], | ||
[ | ||
[0, 0, 0, 1, 1, 1, 1, 1], | ||
[1, 1, 0, 0, 0, 1, 1, 1], | ||
], | ||
] | ||
|
||
for (const [input, expectedResult] of testCases) | ||
expect(circularShiftRight(input, 2)).toEqual(expectedResult) | ||
}) | ||
|
||
test('circularShiftRight with amount 3', () => { | ||
const testCases: Array<[Bits, Bits]> = [ | ||
[ | ||
[1, 0, 0, 0, 1, 1, 0, 1], | ||
[1, 0, 1, 1, 0, 0, 0, 1], | ||
], | ||
[ | ||
[0, 0, 0, 1, 1, 1, 1, 1], | ||
[1, 1, 1, 0, 0, 0, 1, 1], | ||
], | ||
] | ||
|
||
for (const [input, expectedResult] of testCases) | ||
expect(circularShiftRight(input, 3)).toEqual(expectedResult) | ||
}) | ||
|
||
test('circularShiftRight throws when amount too large', () => { | ||
expect(() => circularShiftRight([0, 1], 3)).toThrow() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters