-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
97 lines (77 loc) · 2.5 KB
/
Copy pathindex.test.js
File metadata and controls
97 lines (77 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* eslint-disable */
const { expect } = require("chai")
const countingup = require(".")
const { Counter, add, subtract, multiply, divide, modulo, pow } = countingup
describe("Countingup Library Tests", () => {
describe("Counter Class", () => {
let myCounter
beforeEach(() => {
myCounter = new Counter()
})
it("should initialize with 0 by default", () => {
expect(myCounter.getCurrentNumber()).to.equal(0)
})
it("should initialize with a custom starting number", () => {
const customCounter = new Counter(10)
expect(customCounter.getCurrentNumber()).to.equal(10)
})
it("should increment by 1 by default", () => {
myCounter.count()
expect(myCounter.getCurrentNumber()).to.equal(1)
})
it("should increment by a custom amount", () => {
myCounter.count(5)
expect(myCounter.getCurrentNumber()).to.equal(5)
})
it("should count in reverse when specified", () => {
myCounter.count(10) // start at 10
myCounter.count(3, Counter.DIRECTION.REVERSE)
expect(myCounter.getCurrentNumber()).to.equal(7)
})
it("should reset to 0", () => {
myCounter.count(5)
myCounter.reset()
expect(myCounter.getCurrentNumber()).to.equal(0)
})
it("should reset to a custom number", () => {
myCounter.count(5)
myCounter.reset(100)
expect(myCounter.getCurrentNumber()).to.equal(100)
})
})
describe("Math Utilities", () => {
it("should add numbers correctly", () => {
expect(add(10, 5)).to.equal(15)
})
it("should handle numeric strings in addition", () => {
expect(add("10", "5")).to.equal(15)
})
it("should subtract numbers correctly", () => {
expect(subtract(20, 5)).to.equal(15)
})
it("should multiply numbers correctly", () => {
expect(multiply(3, 4)).to.equal(12)
})
it("should divide numbers correctly", () => {
expect(divide(100, 4)).to.equal(25)
})
it("should calculate modulo correctly", () => {
expect(modulo(10, 3)).to.equal(1)
})
it("should calculate power correctly", () => {
expect(pow(2, 3)).to.equal(8)
})
})
describe("Constants", () => {
it("should match Math constants", () => {
expect(countingup.PI).to.equal(Math.PI)
expect(countingup.E).to.equal(Math.E)
})
it("should have a valid ZERO constant", () => {
expect(countingup.ZERO).to.equal(0)
})
it("should handle NaN correctly", () => {
expect(countingup.NaN).to.be.NaN
})
})
})