65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import bit from "./bit"
|
|
|
|
describe("bit", () => {
|
|
test("can be created from a 0", () => {
|
|
expect(bit(0).value).toBe(0)
|
|
})
|
|
|
|
test("can be created from a 1", () => {
|
|
expect(bit(1).value).toBe(1)
|
|
})
|
|
|
|
test("is equal to other bit when both values are 1", () => {
|
|
expect(bit(1).equals(bit(1))).toBe(true)
|
|
})
|
|
|
|
test("is equal to other bit when both values are 0", () => {
|
|
expect(bit(0).equals(bit(0))).toBe(true)
|
|
})
|
|
|
|
test("is not equal to other bit when value is 0 and other value is 1", () => {
|
|
expect(bit(0).equals(bit(1))).toBe(false)
|
|
})
|
|
|
|
test("is not equal to other bit when value is 1 and other value is 0", () => {
|
|
expect(bit(1).equals(bit(0))).toBe(false)
|
|
})
|
|
|
|
describe("addition", () => {
|
|
describe("sum", () => {
|
|
test("is 0 given 0 and 0", () => {
|
|
expect(bit(0).add(bit(0)).ones.value).toBe(0)
|
|
})
|
|
|
|
test("is 1 given 1 and 0", () => {
|
|
expect(bit(1).add(bit(0)).ones.value).toBe(1)
|
|
})
|
|
|
|
test("is 1 given 0 and 1", () => {
|
|
expect(bit(0).add(bit(1)).ones.value).toBe(1)
|
|
})
|
|
|
|
test("is 0 given 1 and 1", () => {
|
|
expect(bit(1).add(bit(1)).ones.value).toBe(0)
|
|
})
|
|
})
|
|
|
|
describe("carry", () => {
|
|
test("is 0 given 0 and 0", () => {
|
|
expect(bit(0).add(bit(0)).carry.value).toBe(0)
|
|
})
|
|
|
|
test("is 0 given 1 and 0", () => {
|
|
expect(bit(1).add(bit(0)).carry.value).toBe(0)
|
|
})
|
|
|
|
test("is 0 given 0 and 1", () => {
|
|
expect(bit(0).add(bit(1)).carry.value).toBe(0)
|
|
})
|
|
|
|
test("is 1 given 1 and 1", () => {
|
|
expect(bit(1).add(bit(1)).carry.value).toBe(1)
|
|
})
|
|
})
|
|
})
|
|
}) |