-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplexity-calculator.test.js
86 lines (70 loc) · 2.76 KB
/
complexity-calculator.test.js
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
/* global describe, it, beforeEach, expect */
const ComplexityCalculator = require('./complexity-calculator')
describe('complexity calculator tests', () => {
describe('whitespace complexity', () => {
let calculator
beforeEach(() => {
calculator = new ComplexityCalculator(2)
})
it('should return 0 when no whitespaces', () => {
const result = calculator.whiteSpaceComplexity('nospacesarepresent')
expect(result).toBe(0)
})
it('should return 0 when 1 spaces is present', () => {
const result = calculator.whiteSpaceComplexity(' 1space')
expect(result).toBe(0)
})
it('should return 1 when 2 spaces are present', () => {
const result = calculator.whiteSpaceComplexity(' 2paces')
expect(result).toBe(1)
})
it('should return 1 when 3 spaces are present', () => {
const result = calculator.whiteSpaceComplexity(' 3spaces')
expect(result).toBe(1)
})
it('should return 2 when 4 spaces are present', () => {
const result = calculator.whiteSpaceComplexity(' 4spaces')
expect(result).toBe(2)
})
it('should return 0 when no text after spaces', () => {
const result = calculator.whiteSpaceComplexity(' ')
expect(result).toBe(0)
})
it('should return 0 when empty string', () => {
const result = calculator.whiteSpaceComplexity('')
expect(result).toBe(0)
})
it('should return 0 when spaces in the middle', () => {
const result = calculator.whiteSpaceComplexity('spaces in the middle ')
expect(result).toBe(0)
})
it('should return 1 when 1 tab is present', () => {
const result = calculator.whiteSpaceComplexity('\t1tab')
expect(result).toBe(1)
})
it('should return 2 when 2 tabs are present', () => {
const result = calculator.whiteSpaceComplexity('\t\t2tabs')
expect(result).toBe(2)
})
it('should return 2 when 2 space and 2 tab are present', () => {
const result = calculator.whiteSpaceComplexity(' \t\t2spacesAnd2tabs')
expect(result).toBe(2)
})
it('should return 1 when 1 tab at beginning and 1 in the middle are present', () => {
const result = calculator.whiteSpaceComplexity('\t1tabInFront1tabInThe\tmiddle')
expect(result).toBe(1)
})
it('should return 0 when tabs in the middle are present', () => {
const result = calculator.whiteSpaceComplexity('tabs\tin\tthe\tmiddle\t')
expect(result).toBe(0)
})
it('should return 0 when no text after tab', () => {
const result = calculator.whiteSpaceComplexity('\t')
expect(result).toBe(0)
})
it('should set tabLength 2 when no value passed to the constructor', () => {
const calc = new ComplexityCalculator()
expect(calc._tabLength).toBe(2)
})
})
})