Skip to content

Commit 6ae2115

Browse files
authored
Merge pull request #3 from ordo-one/format
format code
2 parents 9b6ce0d + 6e45feb commit 6ae2115

File tree

5 files changed

+65
-56
lines changed

5 files changed

+65
-56
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let package: Package = .init(
99
],
1010
dependencies: [
1111
.package(url: "https://github.com/apple/swift-numerics", from: "1.0.3"),
12+
.package(url: "https://github.com/tayloraswift/dollup", from: "0.5.0"),
1213
],
1314
targets: [
1415
.target(

Sources/RandomTests/Distributions/BinomialTests.swift

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
import Random
22
import Testing
33

4-
@Suite
5-
struct BinomialTests {
4+
@Suite struct BinomialTests {
65
private var random: PseudoRandom
76

87
init() {
98
self.random = .init(seed: 3)
109
}
1110
}
1211
extension BinomialTests {
13-
@Test(arguments: [
14-
(n: 10, p: 0.5),
15-
(n: 20, p: 0.5),
16-
(n: 50, p: 0.5),
17-
(n: 100, p: 0.5),
18-
(n: 200, p: 0.5),
19-
(n: 500, p: 0.5),
20-
(n: 500, p: 0.1),
21-
(n: 500, p: 0.01),
22-
(n: 5_000, p: 0.01),
23-
(n: 50_000, p: 0.001),
24-
])
25-
mutating func Statistics(_ n: Int64, _ p: Double) {
12+
@Test(
13+
arguments: [
14+
(n: 10, p: 0.5),
15+
(n: 20, p: 0.5),
16+
(n: 50, p: 0.5),
17+
(n: 100, p: 0.5),
18+
(n: 200, p: 0.5),
19+
(n: 500, p: 0.5),
20+
(n: 500, p: 0.1),
21+
(n: 500, p: 0.01),
22+
(n: 5_000, p: 0.01),
23+
(n: 50_000, p: 0.001),
24+
]
25+
) mutating func Statistics(_ n: Int64, _ p: Double) {
2626
Binomial[n, p].performStandardStatisticalTests(
2727
sampleCount: 2_000_000,
2828
using: &self.random,
2929
visualize: true
3030
)
3131
}
3232

33-
@Test(arguments: [
34-
(n: 1_000_000, p: 0.0001), // Very large n, very small p
35-
(n: 10_000_000, p: 0.00001), // Extremely large n, extremely small p
36-
(n: 100_000, p: 0.9999), // Large n, p close to 1
37-
(n: 5_000_000, p: 0.5), // Very large n, balanced p
38-
])
39-
mutating func ExtremeValues(_ n: Int64, _ p: Double) {
33+
@Test(
34+
arguments: [
35+
(n: 1_000_000, p: 0.0001), // Very large n, very small p
36+
(n: 10_000_000, p: 0.00001), // Extremely large n, extremely small p
37+
(n: 100_000, p: 0.9999), // Large n, p close to 1
38+
(n: 5_000_000, p: 0.5), // Very large n, balanced p
39+
]
40+
) mutating func ExtremeValues(_ n: Int64, _ p: Double) {
4041
Binomial[n, p].performStandardStatisticalTests(
4142
sampleCount: 1_000_000,
4243
using: &self.random,

Sources/RandomTests/Distributions/Normal (ext).swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ extension Normal: StatisticsTestable {
2525
if self.σ <= 0 { return [] }
2626

2727
let chiSquareBins: Int = 20
28-
let testRange: (min: Double, max: Double) = (min: self.μ - 4 * self.σ, max: self.μ + 4 * self.σ)
28+
let testRange: (min: Double, max: Double) = (
29+
min: self.μ - 4 * self.σ,
30+
max: self.μ + 4 * self.σ
31+
)
2932
let binWidth: Double = (testRange.max - testRange.min) / Double.init(chiSquareBins)
3033

3134
var observedCounts: [Int] = .init(repeating: 0, count: chiSquareBins)
@@ -42,7 +45,10 @@ extension Normal: StatisticsTestable {
4245
let binMin: Double = testRange.min + Double.init($0) * binWidth
4346
let binMax: Double = binMin + binWidth
4447
let expectedProbability: Double = self.cdf(binMax) - self.cdf(binMin)
45-
return .init(observed: observedCounts[$0], expected: Double.init(sampleCount) * expectedProbability)
48+
return .init(
49+
observed: observedCounts[$0],
50+
expected: Double.init(sampleCount) * expectedProbability
51+
)
4652
}
4753
}
4854

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import Random
22
import Testing
33

4-
@Suite
5-
struct NormalTests {
4+
@Suite struct NormalTests {
65
private var random: PseudoRandom
76

87
init() {
@@ -11,25 +10,27 @@ struct NormalTests {
1110
}
1211

1312
extension NormalTests {
14-
@Test(arguments: [
15-
(μ: 0, σ: 1),
16-
(μ: 5, σ: 2),
17-
(μ: 10, σ: 2),
18-
(μ: -5, σ: 3),
19-
(μ: 100, σ: 10),
20-
(μ: 0, σ: 0.1),
21-
])
22-
mutating func Statistics2(_ μ: Double, _ σ: Double) {
13+
@Test(
14+
arguments: [
15+
(μ: 0, σ: 1),
16+
(μ: 5, σ: 2),
17+
(μ: 10, σ: 2),
18+
(μ: -5, σ: 3),
19+
(μ: 100, σ: 10),
20+
(μ: 0, σ: 0.1),
21+
]
22+
) mutating func Statistics2(_ μ: Double, _ σ: Double) {
2323
Normal[μ, σ].performStandardStatisticalTests(using: &self.random, visualize: true)
2424
}
2525

26-
@Test(arguments: [
27-
(μ: 0, σ: 0.001), // Very small variance
28-
(μ: 1e6, σ: 1e3), // Very large mean
29-
(μ: -1e6, σ: 1e3), // Very negative mean
30-
(μ: 0, σ: 0), // Zero variance
31-
])
32-
mutating func ExtremeValues(_ μ: Double, _ σ: Double) {
26+
@Test(
27+
arguments: [
28+
(μ: 0, σ: 0.001), // Very small variance
29+
(μ: 1e6, σ: 1e3), // Very large mean
30+
(μ: -1e6, σ: 1e3), // Very negative mean
31+
(μ: 0, σ: 0), // Zero variance
32+
]
33+
) mutating func ExtremeValues(_ μ: Double, _ σ: Double) {
3334
Normal[μ, σ].performStandardStatisticalTests(using: &self.random, visualize: false)
3435
}
3536
}

Sources/RandomTests/HistogramVisualization.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,21 @@ extension HistogramVisualization {
129129

130130
private func printTableHeader() {
131131
let header: String = """
132-
\(self.valueLabel.padding(left: self.columnWidths.value)) \
133-
| Count \
134-
| Actual % \
135-
| Expected % \
136-
| Actual \("".padding(right: self.columnWidths.bar - 7)) \
137-
| Expected
138-
"""
132+
\(self.valueLabel.padding(left: self.columnWidths.value)) \
133+
| Count \
134+
| Actual % \
135+
| Expected % \
136+
| Actual \("".padding(right: self.columnWidths.bar - 7)) \
137+
| Expected
138+
"""
139139
let separator: String = """
140-
\(String.init(repeating: "-", count: self.columnWidths.value))--\
141-
+-------------\
142-
+--------------\
143-
+--------------\
144-
+----------------------\
145-
+----------------------
146-
"""
140+
\(String.init(repeating: "-", count: self.columnWidths.value))--\
141+
+-------------\
142+
+--------------\
143+
+--------------\
144+
+----------------------\
145+
+----------------------
146+
"""
147147
print(header)
148148
print(separator)
149149
}

0 commit comments

Comments
 (0)