-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsolution.test.js
73 lines (49 loc) · 1.14 KB
/
solution.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
const minimumSwap = require('./solution')
test('Example 1', () => {
const s1 = 'xx'
const s2 = 'yy'
const result = minimumSwap(s1, s2)
expect(result).toBe(1)
})
test('Example 2', () => {
const s1 = 'xy'
const s2 = 'yx'
const result = minimumSwap(s1, s2)
expect(result).toBe(2)
})
test('Example 3', () => {
const s1 = 'xx'
const s2 = 'xy'
const result = minimumSwap(s1, s2)
expect(result).toBe(-1)
})
test('Example 4', () => {
const s1 = 'xxyyxyxyxx'
const s2 = 'xyyxyxxxyx'
const result = minimumSwap(s1, s2)
expect(result).toBe(4)
})
test('same string', () => {
const s1 = 'xy'
const s2 = 'xy'
const result = minimumSwap(s1, s2)
expect(result).toBe(0)
})
test('y0 and y4, should return 2', () => {
const s1 = 'xxxx'
const s2 = 'yyyy'
const result = minimumSwap(s1, s2)
expect(result).toBe(2)
})
test('y1 and y3, should return 3', () => {
const s1 = 'xxxy'
const s2 = 'yyyx'
const result = minimumSwap(s1, s2)
expect(result).toBe(3)
})
test('y2 and y2, should return 2', () => {
const s1 = 'xxyy'
const s2 = 'yyxx'
const result = minimumSwap(s1, s2)
expect(result).toBe(2)
})