-
Notifications
You must be signed in to change notification settings - Fork 106
/
zero-null-EmptyValue.spec.ts
99 lines (87 loc) · 4.61 KB
/
zero-null-EmptyValue.spec.ts
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
98
99
import { HyperFormula, DetailedCellError } from '../../src'
import '../testConfig'
import { adr } from '../testUtils'
import { CellError, ErrorType } from '../../src/Cell'
import { EmptyValue } from '../../src/Cell'
// Data and test scenarios were part of the working draft for GNOME
// https://gxitlab.gnome.org/GNOME/gnumeric/blob/master/samples/excel/operator.xls
const data =
['=A1=B1', '=A1>B1', '=A1<B1', '=A1>=B1', '=A1<=B1', '=A1<>B1', '=A1+B1', '=A1-B1', '=A1*B1', '=A1/B1', '=A1^B1', '=A1&B1', '=+A1', '=-A1', '=A1%']
function createEngine(data: any[][]) {
const engine = HyperFormula.buildFromArray(data)
return {
getCellValue(cellAddress: string) {
return engine.getCellValue(adr(cellAddress))
}
}
}
describe('Quality assurance of comparision of 0, null and EmptyValue', () => {
it('Zero with empty string given directly should be supported by all comparison operators', () => {
const engine = createEngine([
[0, '', ...data]
])
//expect(engine.getCellValue('C1')).toEqual(true) // EQUAL false
//expect(engine.getCellValue('H1')).toEqual(false) // NOT EQUAL true
})
it('Zero with null given directly should be supported by all comparison operators', () => {
const engine = createEngine([
[0, null, ...data]
])
expect(engine.getCellValue('C1')).toEqual(true) // EQUAL
expect(engine.getCellValue('D1')).toEqual(false) // GT
expect(engine.getCellValue('E1')).toEqual(false) // LT true
expect(engine.getCellValue('F1')).toEqual(true) // GTE false
expect(engine.getCellValue('G1')).toEqual(true) // LTE false
expect(engine.getCellValue('H1')).toEqual(false) // NOT EQUAL true
expect(engine.getCellValue('I1')).toEqual(0) // ADD
expect(engine.getCellValue('J1')).toEqual(0) // SUB
expect(engine.getCellValue('K1')).toEqual(0) // MULT
expect(engine.getCellValue('L1')).toEqual(new DetailedCellError(new CellError(ErrorType.DIV_BY_ZERO), '#DIV/0!')) // DIV
//expect(engine.getCellValue('M1')).toEqual(new DetailedCellError(new CellError(ErrorType.NUM), '#NUM!')) // EXP
expect(engine.getCellValue('N1')).toEqual('0') // CONCAT
expect(engine.getCellValue('P1')).toEqual(0) // UNARY PLUS
expect(engine.getCellValue('P1')).toEqual(0) // UNARY MINUS
expect(engine.getCellValue('Q1')).toEqual(0) // PERCENTAGE
})
it('Zero with EmptyValue given by reference should be supported by all comparison operators', () => {
const engine = createEngine([
[0, '=A2', ...data],
[EmptyValue]
])
expect(engine.getCellValue('A1')).toEqual(0)
expect(engine.getCellValue('B1')).toEqual(EmptyValue)
expect(engine.getCellValue('A2')).toEqual(EmptyValue)
expect(engine.getCellValue('C1')).toEqual(true) // EQUAL
expect(engine.getCellValue('D1')).toEqual(false) // GT
expect(engine.getCellValue('E1')).toEqual(false) // LT
expect(engine.getCellValue('F1')).toEqual(true) // GTE
expect(engine.getCellValue('G1')).toEqual(true) // LTE
expect(engine.getCellValue('H1')).toEqual(false) // NOT EQUAL
expect(engine.getCellValue('I1')).toEqual(0) // ADD
expect(engine.getCellValue('J1')).toEqual(0) // SUB
expect(engine.getCellValue('K1')).toEqual(0) // MULT
expect(engine.getCellValue('L1')).toEqual(new DetailedCellError(new CellError(ErrorType.DIV_BY_ZERO), '#DIV/0!')) // DIV
expect(engine.getCellValue('M1')).toEqual(1) // EXP
expect(engine.getCellValue('N1')).toEqual('0') // CONCAT
expect(engine.getCellValue('P1')).toEqual(0) // UNARY PLUS
expect(engine.getCellValue('P1')).toEqual(0) // UNARY MINUS
expect(engine.getCellValue('Q1')).toEqual(0) // PERCENTAGE
})
it('Zero with Zero given directly should be supported by all comparison operators', () => {
const engine = createEngine([
[0, 0, ...data]
])
expect(engine.getCellValue('C1')).toEqual(true) // EQUAL
expect(engine.getCellValue('D1')).toEqual(false) // GT
expect(engine.getCellValue('E1')).toEqual(false) // LT
expect(engine.getCellValue('F1')).toEqual(true) // GTE
expect(engine.getCellValue('G1')).toEqual(true) // LTE
expect(engine.getCellValue('H1')).toEqual(false) // NOT EQUAL
expect(engine.getCellValue('I1')).toEqual(0) // ADD
expect(engine.getCellValue('J1')).toEqual(0) // SUB
expect(engine.getCellValue('K1')).toEqual(0) // MULT
expect(engine.getCellValue('L1')).toEqual(new DetailedCellError(new CellError(ErrorType.DIV_BY_ZERO), '#DIV/0!')) // DIV
expect(engine.getCellValue('M1')).toEqual(1) // EXP
expect(engine.getCellValue('N1')).toEqual('00') // CONCAT
})
})