-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructors.test.ts
More file actions
64 lines (48 loc) · 1.77 KB
/
Copy pathconstructors.test.ts
File metadata and controls
64 lines (48 loc) · 1.77 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
import { Numeric } from '@/lt-22/constructors'
import { describe, it, expect } from 'vitest'
describe('tests of constructors', () => {
it('can be instantiated with a no-arg constructor', () => {
const o: Numeric = new Numeric()
expect(o).toBeInstanceOf(Numeric)
expect(o.asString).toBeNull()
expect(o.asNumeric).toBeNull()
})
it('can be instantiated with a one-arg (string) constructor', () => {
const o: Numeric = new Numeric('forty-two')
expect(o).toBeInstanceOf(Numeric)
expect(o.asString).toEqual('forty-two')
expect(o.asNumeric).toBeNull()
})
it('can be instantiated with a one-arg (number) constructor', () => {
const o: Numeric = new Numeric(42)
expect(o).toBeInstanceOf(Numeric)
expect(o.asString).toBeNull()
expect(o.asNumeric).toEqual(42)
})
it('can be instantiated with a two-arg constructor', () => {
const o: Numeric = new Numeric('forty-two', 42)
expect(o).toBeInstanceOf(Numeric)
expect(o.asString).toEqual('forty-two')
expect(o.asNumeric).toEqual(42)
})
describe('Testing some bugs from the original implementation', () => {
it('accepts an empty string as the only argument', () => {
const o: Numeric = new Numeric('')
expect(o.asString).toEqual('')
expect(o.asNumeric).toBeNull()
})
it('accepts an empty string as the first argument', () => {
const o: Numeric = new Numeric('', -1)
expect(o.asString).toEqual('')
})
it('accepts zero as the only argument', () => {
const o: Numeric = new Numeric(0)
expect(o.asNumeric).toEqual(0)
expect(o.asString).toBeNull()
})
it('accepts zero as the second argument', () => {
const o: Numeric = new Numeric('NOT_TESTED', 0)
expect(o.asNumeric).toEqual(0)
})
})
})