Skip to content

Commit 34b09ec

Browse files
authored
Add Abelian protocol, make AdditiveGroup default implementations public (#222)
1 parent aef5b88 commit 34b09ec

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

Diff for: Sources/Algebra/Abelian.swift

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//
2+
// Abelian.swift
3+
// Algebra
4+
//
5+
// Created by James Bean on 9/6/19.
6+
//
7+
8+
/// Interface defining a `Group` which is also commutative.
9+
public protocol Abelian: Group { }

Diff for: Sources/Algebra/AdditiveGroup.swift

+13-5
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@
55
// Created by Benjamin Wetherfield on 10/11/2018.
66
//
77

8+
/// The requirements for a type to display the behaviors of an `AdditiveGroup`.
9+
///
10+
/// The `AdditiveGroup` builds upon the `AdditiveMonoid` with an `inverse` operation.
811
public protocol AdditiveGroup: Additive, Invertible {
9-
12+
13+
/// - Returns: The additive inverse of this `AdditiveGroup` element.
1014
static prefix func - (_ element: Self) -> Self
15+
16+
/// - Returns: The difference between two `AdditiveGroup` elements.
1117
static func - (lhs: Self, rhs: Self) -> Self
1218
}
1319

1420
extension AdditiveGroup {
15-
16-
static prefix func - (_ element: Self) -> Self {
21+
22+
/// - Returns: The additive inverse of this `AdditiveGroup` element.
23+
public static prefix func - (_ element: Self) -> Self {
1724
return element.inverse
1825
}
19-
20-
static func - (lhs: Self, rhs: Self) -> Self {
26+
27+
/// - Returns: The difference between two `AdditiveGroup` elements.
28+
public static func - (lhs: Self, rhs: Self) -> Self {
2129
return lhs + -rhs
2230
}
2331
}

Diff for: Tests/DataStructuresPerformanceTests/GraphPerformanceTests/GraphPerformanceTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class GraphPerformanceTests: XCTestCase {
5050
XCTAssert(benchmark.performance(is: .constant))
5151
}
5252

53-
#warning("FIXME: Assess why the testEdgeFromSourceInCompleteGraph benchmark test files. It is currently disabled.")
53+
// FIXME: Assess why the testEdgeFromSourceInCompleteGraph benchmark test files
5454
func DISABLED_testEdgeFromSourceInCompleteGraph_O_n() {
5555
let benchmark = Benchmark.mutating(
5656
testPoints: Scale.small,

Diff for: Tests/DataStructuresTests/MatrixTests.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import DataStructures
1212
class MatrixTests: XCTestCase {
1313

1414
func testInit() {
15-
1615
let amountRows = 2
1716
let amountColumns = 3
18-
var matrix = Matrix(height: amountRows, width: amountColumns, initial: 0)
19-
17+
let matrix = Matrix(height: amountRows, width: amountColumns, initial: 0)
2018
for row in 0 ..< amountRows {
2119
for column in 0 ..< amountColumns {
2220
XCTAssertEqual(matrix[row, column], 0)

0 commit comments

Comments
 (0)