Skip to content

Commit 3f556e3

Browse files
refactor: Clean up migrated tests
1 parent 7469811 commit 3f556e3

File tree

8 files changed

+86
-68
lines changed

8 files changed

+86
-68
lines changed

Sources/StatKit/Descriptive Statistics/Association/Correlation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public extension Collection {
123123
}
124124

125125
/// The different supported variants of the Kendall Tau coefficient.
126-
public enum KendallTauVariant: CaseIterable {
126+
public enum KendallTauVariant: CaseIterable, Sendable {
127127
/// The original Tau statistic defined in 1938.
128128
/// Tau-a does not make adjustments for rank ties.
129129
case a

Sources/StatKit/Descriptive Statistics/Central Tendency/MeanStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// An enumeration specififying a type of mean value calculation.
2-
public enum MeanStrategy: CaseIterable {
2+
public enum MeanStrategy: CaseIterable, Sendable {
33
/// A case specifying the arithmetic mean.
44
case arithmetic
55

Sources/StatKit/Descriptive Statistics/Central Tendency/MedianStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// Determines which value to pick in cases where the number of elements in a collection are even.
2-
public enum MedianStrategy {
2+
public enum MedianStrategy: CaseIterable, Sendable {
33
/// Returns the higher of the two middle values if there is an even number of elements in the collection.
44
case high
55
/// Returns the lower of the two middle values if there is an even number of elements in the collection.

Sources/StatKit/Descriptive Statistics/Quantile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public extension Collection {
7777
}
7878

7979
/// A method for computing quantiles.
80-
public enum QuantileEstimationMethod {
80+
public enum QuantileEstimationMethod: CaseIterable, Sendable {
8181
/// Computes the quantile usign the inverse empirical CDF.
8282
case inverseEmpiricalCDF
8383
/// Computes the quantile usign the inverse empirical CDF, and takes the arithmetic mean at discontinuities.

Sources/StatKit/Descriptive Statistics/Ranking/RankingStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protocol RankingStrategyProtocol {
1818
}
1919

2020
/// A calculation strategy for ranking comparable variables.
21-
public enum RankingStrategy {
21+
public enum RankingStrategy: CaseIterable, Sendable {
2222
/// The Fractional ranking strategy.
2323
case fractional
2424
/// The Standard Competition ranking strategy.

Tests/StatKitTests/Descriptive Statistics Tests/Dispersion Tests/VarianceTests.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@ import StatKit
33

44
@Suite("Variance Tests", .tags(.dispersion))
55
struct VarianceTests {
6-
@Test("Valid data returns correct variance", arguments: [
7-
((1 ... 5).map(\.realValue), 2.5, DataSetComposition.sample),
8-
((-5 ... 5).map(\.realValue), 11.0, DataSetComposition.sample),
9-
((1 ... 5).map(\.realValue), 2, DataSetComposition.population),
10-
((-5 ... 5).map(\.realValue), 10, DataSetComposition.population),
11-
])
6+
@Test(
7+
"Valid data returns correct variance",
8+
arguments: [
9+
((1 ... 5).map(\.realValue), 2.5, DataSetComposition.sample),
10+
((-5 ... 5).map(\.realValue), 11.0, DataSetComposition.sample),
11+
((1 ... 5).map(\.realValue), 2, DataSetComposition.population),
12+
((-5 ... 5).map(\.realValue), 10, DataSetComposition.population),
13+
] as [([Double], Double, DataSetComposition)]
14+
)
1215
func validData(data: [Double], expectedVariance: Double, composition: DataSetComposition) {
1316
#expect(data.variance(variable: \.self, from: composition).isApproximatelyEqual(to: expectedVariance, absoluteTolerance: 1e-6))
1417
}

Tests/StatKitTests/Descriptive Statistics Tests/Ranking Tests/RankingTests.swift

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,86 +3,101 @@ import StatKit
33

44
@Suite("Ranking Tests", .tags(.ranking))
55
struct RankingTests {
6-
private typealias RankingInput<T> = [([T], (T, T) -> Bool, [Double], RankingStrategy)]
6+
private typealias RankingInput<T> = [([T], [Double], RankingStrategy)]
77

88
@Test(
9-
"Valid integer data sets produce valid rankings",
9+
"Valid integer data sets produce valid rankings for less than ordering",
1010
arguments: [
11-
([1, 2, 3, 4, 5], >, [5, 4, 3, 2, 1], .dense),
12-
([1, 3, 4, 3, 5], >, [4, 3, 2, 3, 1], .dense),
13-
([1, 2, 3, 4, 5], <, [1, 2, 3, 4, 5], .dense),
14-
([1, 3, 4, 3, 5], <, [1, 2, 3, 2, 4], .dense),
15-
([], <, [], .dense),
16-
([1], <, [1], .dense),
17-
([1, 3, 5, 3], <=, [1, 2, 3, 2], .dense),
18-
19-
([1, 3, 4, 2, 5], >, [5, 3, 2, 4, 1], .fractional),
20-
([1, 3, 4, 3, 5], >, [5, 3.5, 2, 3.5, 1], .fractional),
21-
([1, 3, 4, 2, 5], <, [1, 3, 4, 2, 5], .fractional),
22-
([1, 3, 4, 3, 5], <, [1, 2.5, 4, 2.5, 5], .fractional),
23-
([], <, [], .fractional),
24-
([1], <, [1], .fractional),
25-
([1, 3, 5, 3], <=, [1, 2.5, 4, 2.5], .fractional),
26-
27-
([1, 3, 4, 2, 5], >, [5, 3, 2, 4, 1], .modifiedCompetition),
28-
([1, 3, 4, 3, 5], >, [5, 4, 2, 4, 1], .modifiedCompetition),
29-
([1, 3, 4, 2, 5], <, [1, 3, 4, 2, 5], .modifiedCompetition),
30-
([1, 3, 4, 3, 5, 3, 3], <, [1, 5, 6, 5, 7, 5, 5], .modifiedCompetition),
31-
([], <, [], .modifiedCompetition),
32-
([1], <, [1], .modifiedCompetition),
33-
([1, 3, 5, 3], <=, [1, 3, 4, 3], .modifiedCompetition),
34-
35-
([1, 3, 4, 2, 5], >, [5, 3, 2, 4, 1], .standardCompetition),
36-
([1, 3, 4, 3, 5], >, [5, 3, 2, 3, 1], .standardCompetition),
37-
([1, 3, 4, 2, 5], <, [1, 3, 4, 2, 5], .standardCompetition),
38-
([1, 3, 4, 3, 5, 3, 3], <, [1, 2, 6, 2, 7, 2, 2], .standardCompetition),
39-
([], <, [], .standardCompetition),
40-
([1], <, [1], .standardCompetition),
41-
([1, 3, 5, 3], <=, [1, 2, 4, 2], .standardCompetition),
42-
43-
([1, 3, 4, 2, 5], >, [5, 3, 2, 4, 1], .ordinal),
44-
([1, 3, 4, 3, 5], >, [5, 3, 2, 4, 1], .ordinal),
45-
([1, 3, 4, 2, 5], <, [1, 3, 4, 2, 5], .ordinal),
46-
([1, 3, 4, 3, 5, 3, 3], <, [1, 2, 6, 3, 7, 4, 5], .ordinal),
47-
([], <, [], .ordinal),
48-
([1], <, [1], .ordinal),
49-
([1, 3, 5, 3], <=, [1, 2, 4, 3], .ordinal),
11+
([1, 2, 3, 4, 5], [1, 2, 3, 4, 5], .dense),
12+
([1, 3, 4, 3, 5], [1, 2, 3, 2, 4], .dense),
13+
([], [], .dense),
14+
([1], [1], .dense),
15+
([1, 3, 5, 3], [1, 2, 3, 2], .dense),
16+
17+
([1, 3, 4, 2, 5], [1, 3, 4, 2, 5], .fractional),
18+
([1, 3, 4, 3, 5], [1, 2.5, 4, 2.5, 5], .fractional),
19+
([], [], .fractional),
20+
([1], [1], .fractional),
21+
([1, 3, 5, 3], [1, 2.5, 4, 2.5], .fractional),
22+
23+
([1, 3, 4, 2, 5], [1, 3, 4, 2, 5], .modifiedCompetition),
24+
([1, 3, 4, 3, 5, 3, 3], [1, 5, 6, 5, 7, 5, 5], .modifiedCompetition),
25+
([], [], .modifiedCompetition),
26+
([1], [1], .modifiedCompetition),
27+
([1, 3, 5, 3], [1, 3, 4, 3], .modifiedCompetition),
28+
29+
([1, 3, 4, 2, 5], [1, 3, 4, 2, 5], .standardCompetition),
30+
([1, 3, 4, 3, 5, 3, 3], [1, 2, 6, 2, 7, 2, 2], .standardCompetition),
31+
([], [], .standardCompetition),
32+
([1], [1], .standardCompetition),
33+
([1, 3, 5, 3], [1, 2, 4, 2], .standardCompetition),
34+
35+
([1, 3, 4, 2, 5], [1, 3, 4, 2, 5], .ordinal),
36+
([1, 3, 4, 3, 5, 3, 3], [1, 2, 6, 3, 7, 4, 5], .ordinal),
37+
([], [], .ordinal),
38+
([1], [1], .ordinal),
39+
([1, 3, 5, 3], [1, 2, 4, 3], .ordinal),
40+
] as RankingInput<Int>
41+
)
42+
func validIntegerDataSetsLessThanOrdering(
43+
data: [Int],
44+
expectedRank: [Double],
45+
strategy: RankingStrategy
46+
) async {
47+
#expect(data.rank(variable: \.self, by: <, strategy: strategy) == expectedRank)
48+
}
49+
50+
@Test(
51+
"Valid integer data sets produce valid rankings for greater than ordering",
52+
arguments: [
53+
([1, 2, 3, 4, 5], [5, 4, 3, 2, 1], .dense),
54+
([1, 3, 4, 3, 5], [4, 3, 2, 3, 1], .dense),
55+
56+
([1, 3, 4, 2, 5], [5, 3, 2, 4, 1], .fractional),
57+
([1, 3, 4, 3, 5], [5, 3.5, 2, 3.5, 1], .fractional),
58+
59+
([1, 3, 4, 2, 5], [5, 3, 2, 4, 1], .modifiedCompetition),
60+
([1, 3, 4, 3, 5], [5, 4, 2, 4, 1], .modifiedCompetition),
61+
62+
([1, 3, 4, 2, 5], [5, 3, 2, 4, 1], .standardCompetition),
63+
([1, 3, 4, 3, 5], [5, 3, 2, 3, 1], .standardCompetition),
64+
65+
([1, 3, 4, 2, 5], [5, 3, 2, 4, 1], .ordinal),
66+
([1, 3, 4, 3, 5], [5, 3, 2, 4, 1], .ordinal),
5067
] as RankingInput<Int>
5168
)
52-
func validIntegerDataSets(
69+
func validIntegerDataSetsGreaterThanOrdering(
5370
data: [Int],
54-
ordering: @escaping (Int, Int) -> Bool,
5571
expectedRank: [Double],
5672
strategy: RankingStrategy
5773
) async {
58-
#expect(data.rank(variable: \.self, by: ordering, strategy: strategy) == expectedRank)
74+
#expect(data.rank(variable: \.self, by: >, strategy: strategy) == expectedRank)
5975
}
6076

6177
@Test(
6278
"Valid floating point data sets produce valid rankings",
6379
arguments: [
64-
([.infinity, .pi, -.infinity, -.pi], <, [4, 3, 1, 2], .dense),
65-
([-.infinity, -.infinity, .infinity, .infinity], <, [1, 1, 2, 2], .dense),
80+
([.infinity, .pi, -.infinity, -.pi], [4, 3, 1, 2], .dense),
81+
([-.infinity, -.infinity, .infinity, .infinity], [1, 1, 2, 2], .dense),
6682
67-
([.infinity, .pi, -.infinity, -.pi], <, [4, 3, 1, 2], .fractional),
68-
([-.infinity, -.infinity, .infinity, .infinity], <, [1.5, 1.5, 3.5, 3.5], .fractional),
83+
([.infinity, .pi, -.infinity, -.pi], [4, 3, 1, 2], .fractional),
84+
([-.infinity, -.infinity, .infinity, .infinity], [1.5, 1.5, 3.5, 3.5], .fractional),
6985
70-
([.infinity, .pi, -.infinity, -.pi], <, [4, 3, 1, 2], .modifiedCompetition),
71-
([-.infinity, -.infinity, .infinity, .infinity], <, [2, 2, 4, 4], .modifiedCompetition),
86+
([.infinity, .pi, -.infinity, -.pi], [4, 3, 1, 2], .modifiedCompetition),
87+
([-.infinity, -.infinity, .infinity, .infinity], [2, 2, 4, 4], .modifiedCompetition),
7288
73-
([.infinity, .pi, -.infinity, -.pi], <, [4, 3, 1, 2], .standardCompetition),
74-
([-.infinity, -.infinity, .infinity, .infinity], <, [1, 1, 3, 3], .standardCompetition),
89+
([.infinity, .pi, -.infinity, -.pi], [4, 3, 1, 2], .standardCompetition),
90+
([-.infinity, -.infinity, .infinity, .infinity], [1, 1, 3, 3], .standardCompetition),
7591
76-
([.infinity, .pi, -.infinity, -.pi], <, [4, 3, 1, 2], .ordinal),
77-
([-.infinity, -.infinity, .infinity, .infinity], <, [1, 2, 3, 4], .ordinal),
92+
([.infinity, .pi, -.infinity, -.pi], [4, 3, 1, 2], .ordinal),
93+
([-.infinity, -.infinity, .infinity, .infinity], [1, 2, 3, 4], .ordinal),
7894
] as RankingInput<Double>
7995
)
8096
func validFloatingPointDataSets(
8197
data: [Double],
82-
ordering: @escaping (Double, Double) -> Bool,
8398
expectedRank: [Double],
8499
strategy: RankingStrategy
85100
) async {
86-
#expect(data.rank(variable: \.self, by: ordering, strategy: strategy) == expectedRank)
101+
#expect(data.rank(variable: \.self, by: <, strategy: strategy) == expectedRank)
87102
}
88103
}

Tests/StatKitTests/Descriptive Statistics Tests/SummationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct SummationTests {
2424
([1, 2, 3, 4, .infinity], .infinity),
2525
] as [([Double], Double)]
2626
)
27-
func validIntegerData(data: [Double], expectedSum: Double) {
27+
func validFloatingPointData(data: [Double], expectedSum: Double) {
2828
#expect(data.sum(over: \.self) == expectedSum)
2929
}
3030

0 commit comments

Comments
 (0)