Skip to content

Commit 77aad73

Browse files
committed
move actual above expected in tests
1 parent 105f01a commit 77aad73

5 files changed

+27
-28
lines changed

combinations_test.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ Deno.test("r = -1", () => {
1717
});
1818

1919
Deno.test("r = n = 0", () => {
20-
const expected = [[]];
2120
const actual = [...combinations(0, "")];
21+
const expected = [[]];
2222
assertEquals(actual, expected);
2323
});
2424

2525
Deno.test("r = 0", () => {
26-
const expected = [[]];
2726
const actual = [...combinations(0, "abc")];
27+
const expected = [[]];
2828
assertEquals(actual, expected);
2929
});
3030

@@ -34,25 +34,24 @@ Deno.test("n = 0", () => {
3434
});
3535

3636
Deno.test("r > n", () => {
37-
const expected: Iterable<string[]> = [];
3837
const actual = [...combinations(32, "abc")];
39-
assertEquals(actual, expected);
38+
assertEquals(actual, []);
4039
});
4140

4241
Deno.test("r = n", () => {
43-
const expected = [["a", "b", "c"]];
4442
const actual = [...combinations(3, "abc")];
43+
const expected = [["a", "b", "c"]];
4544
assertEquals(actual, expected);
4645
});
4746

4847
Deno.test("r < n", () => {
48+
const actual = [...combinations(3, [0, 1, 2, 3])];
4949
const expected = [
5050
[0, 1, 2],
5151
[0, 1, 3],
5252
[0, 2, 3],
5353
[1, 2, 3],
5454
];
55-
const actual = [...combinations(3, [0, 1, 2, 3])];
5655
assertEquals(actual, expected);
5756
});
5857

@@ -71,7 +70,7 @@ for (let n = 0; n < 8; n++) {
7170
}
7271
}
7372

74-
/** Return the number of ways to choose `r` items from `n` items without repetition and without order. */
73+
/** Return the number of ways to choose `r` items from `n` items without replacement and without order. */
7574
function comb(n: number, r: number): number {
7675
if (n < 0 || !Number.isInteger(n)) {
7776
throw RangeError("n must be a non-negative integer");

combinations_with_replacement_test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Deno.test("r = -1", () => {
1616
});
1717

1818
Deno.test("r = n = 0", () => {
19-
const expected = [[]];
2019
const actual = [...combinationsWithReplacement(0, "")];
20+
const expected = [[]];
2121
assertEquals(actual, expected);
2222
});
2323

2424
Deno.test("r = 0", () => {
25-
const expected = [[]];
2625
const actual = [...combinationsWithReplacement(0, "abc")];
26+
const expected = [[]];
2727
assertEquals(actual, expected);
2828
});
2929

@@ -33,6 +33,7 @@ Deno.test("n = 0", () => {
3333
});
3434

3535
Deno.test("r > n", () => {
36+
const actual = [...combinationsWithReplacement(4, "abc")];
3637
const expected = [
3738
["a", "a", "a", "a"],
3839
["a", "a", "a", "b"],
@@ -50,11 +51,11 @@ Deno.test("r > n", () => {
5051
["b", "c", "c", "c"],
5152
["c", "c", "c", "c"],
5253
];
53-
const actual = [...combinationsWithReplacement(4, "abc")];
5454
assertEquals(actual, expected);
5555
});
5656

5757
Deno.test("r = n", () => {
58+
const actual = [...combinationsWithReplacement(3, "abc")];
5859
const expected = [
5960
["a", "a", "a"],
6061
["a", "a", "b"],
@@ -67,11 +68,11 @@ Deno.test("r = n", () => {
6768
["b", "c", "c"],
6869
["c", "c", "c"],
6970
];
70-
const actual = [...combinationsWithReplacement(3, "abc")];
7171
assertEquals(actual, expected);
7272
});
7373

7474
Deno.test("r < n", () => {
75+
const actual = [...combinationsWithReplacement(2, [0, 1, 2])];
7576
const expected = [
7677
[0, 0],
7778
[0, 1],
@@ -80,7 +81,6 @@ Deno.test("r < n", () => {
8081
[1, 2],
8182
[2, 2],
8283
];
83-
const actual = [...combinationsWithReplacement(2, [0, 1, 2])];
8484
assertEquals(actual, expected);
8585
});
8686

@@ -112,7 +112,7 @@ function cwr(n: number, r: number): number {
112112
}
113113
}
114114

115-
/** Equivalent to `combinationsWithReplacement1` for testing. */
115+
/** Equivalent to `combinationsWithReplacement` for testing. */
116116
function* combinationsWithReplacement1<T>(
117117
r: number,
118118
iterable: Iterable<T>,

permutations_test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ Deno.test("r = -1", () => {
1616
});
1717

1818
Deno.test("r = n = 0", () => {
19-
const expected = [[]];
2019
const actual = [...permutations(0, "")];
20+
const expected = [[]];
2121
assertEquals(actual, expected);
2222
});
2323

2424
Deno.test("r = 0", () => {
25-
const expected = [[]];
2625
const actual = [...permutations(0, "abc")];
26+
const expected = [[]];
2727
assertEquals(actual, expected);
2828
});
2929

@@ -33,12 +33,13 @@ Deno.test("n = 0", () => {
3333
});
3434

3535
Deno.test("r > n", () => {
36-
const expected: Iterable<string[]> = [];
3736
const actual = [...permutations(4, "abc")];
37+
const expected: Iterable<string[]> = [];
3838
assertEquals(actual, expected);
3939
});
4040

4141
Deno.test("r = n", () => {
42+
const actual = [...permutations(3, "abc")];
4243
const expected = [
4344
["a", "b", "c"],
4445
["a", "c", "b"],
@@ -47,11 +48,11 @@ Deno.test("r = n", () => {
4748
["c", "a", "b"],
4849
["c", "b", "a"],
4950
];
50-
const actual = [...permutations(3, "abc")];
5151
assertEquals(actual, expected);
5252
});
5353

5454
Deno.test("r < n", () => {
55+
const actual = [...permutations(3, [0, 1, 2, 3])];
5556
const expected = [
5657
[0, 1, 2],
5758
[0, 1, 3],
@@ -78,7 +79,6 @@ Deno.test("r < n", () => {
7879
[3, 2, 0],
7980
[3, 2, 1],
8081
];
81-
const actual = [...permutations(3, [0, 1, 2, 3])];
8282
assertEquals(actual, expected);
8383
});
8484

power_set_test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function* powerSet1<T>(iterable: Iterable<T>): Generator<T[]> {
7272
}
7373
}
7474

75-
/** Equivalent to `product` for testing. */
75+
/** Equivalent to `powerSet` for testing. */
7676
function* powerSet2<T>(iterable: Iterable<T>): Generator<T[]> {
7777
const pool = [...iterable];
7878
const n = pool.length;
@@ -82,7 +82,7 @@ function* powerSet2<T>(iterable: Iterable<T>): Generator<T[]> {
8282
}
8383
}
8484

85-
/** Equivalent to `product` for testing. */
85+
/** Equivalent to `powerSet` for testing. */
8686
function* powerSet3<T>(iterable: Iterable<T>): Generator<T[]> {
8787
const pool = [...iterable];
8888
const n = pool.length;

product_test.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Deno.test("r = -1", () => {
1414
});
1515

1616
Deno.test("r = n = 0", () => {
17-
const expected = [[]];
1817
const actual = [...product(0, "")];
18+
const expected = [[]];
1919
assertEquals(actual, expected);
2020
});
2121

2222
Deno.test("r = 0", () => {
23-
const expected = [[]];
2423
const actual = [...product(0, "abc")];
24+
const expected = [[]];
2525
assertEquals(actual, expected);
2626
});
2727

@@ -31,6 +31,7 @@ Deno.test("n = 0", () => {
3131
});
3232

3333
Deno.test("r > n", () => {
34+
const actual = [...product(3, "ab")];
3435
const expected = [
3536
["a", "a", "a"],
3637
["a", "a", "b"],
@@ -41,11 +42,11 @@ Deno.test("r > n", () => {
4142
["b", "b", "a"],
4243
["b", "b", "b"],
4344
];
44-
const actual = [...product(3, "ab")];
4545
assertEquals(actual, expected);
4646
});
4747

4848
Deno.test("r = n", () => {
49+
const actual = [...product(3, [1, 2, 3])];
4950
const expected = [
5051
[1, 1, 1],
5152
[1, 1, 2],
@@ -75,11 +76,11 @@ Deno.test("r = n", () => {
7576
[3, 3, 2],
7677
[3, 3, 3],
7778
];
78-
const actual = [...product(3, [1, 2, 3])];
7979
assertEquals(actual, expected);
8080
});
8181

8282
Deno.test("r < n", () => {
83+
const actual = [...product(2, [1, 2, 3])];
8384
const expected = [
8485
[1, 1],
8586
[1, 2],
@@ -91,17 +92,17 @@ Deno.test("r < n", () => {
9192
[3, 2],
9293
[3, 3],
9394
];
94-
const actual = [...product(2, [1, 2, 3])];
9595
assertEquals(actual, expected);
9696
});
9797

9898
Deno.test("r > n with two iterables", () => {
99-
const expected = [[1, 2, 1, 2, 1, 2]];
10099
const actual = [...product(3, [1], [2])];
100+
const expected = [[1, 2, 1, 2, 1, 2]];
101101
assertEquals(actual, expected);
102102
});
103103

104104
Deno.test("r = n with two iterables", () => {
105+
const actual = [...product(3, [1, 2], [3])];
105106
const expected = [
106107
[1, 3, 1, 3, 1, 3],
107108
[1, 3, 1, 3, 2, 3],
@@ -112,13 +113,12 @@ Deno.test("r = n with two iterables", () => {
112113
[2, 3, 2, 3, 1, 3],
113114
[2, 3, 2, 3, 2, 3],
114115
];
115-
const actual = [...product(3, [1, 2], [3])];
116116
assertEquals(actual, expected);
117117
});
118118

119119
Deno.test("r < n with two iterables", () => {
120-
const expected = [[1, 3], [1, 4], [2, 3], [2, 4]];
121120
const actual = [...product(1, [1, 2], [3, 4])];
121+
const expected = [[1, 3], [1, 4], [2, 3], [2, 4]];
122122
assertEquals(actual, expected);
123123
});
124124

0 commit comments

Comments
 (0)