Skip to content

Commit

Permalink
Migrate tests to swift-testing (#22)
Browse files Browse the repository at this point in the history
The tests were migrated to swift-testing because it is supported on
Windows unlike Nimble. Furthermore, I added a job for running the tests
on Windows to the pipeline. Since the project does not rely anymore on
Quick and Nimble for the tests, I removed the packages. swift-testing
does not have to be included as dependency.

I removed SwiftDependencyGraphsTests because the file was generated by
XCode or SwiftPM and I did not use it. I split
ContainsVertexWithTests.swift since I found the file too big and I lost
the overview.

Closes #15
See pull request #22
  • Loading branch information
ikelax authored Jan 28, 2025
1 parent 3672335 commit 06fd03e
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 214 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,18 @@ jobs:
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
brew install xcbeautify
set -o pipefail && swift test | xcbeautify --renderer github-actions
test-windows:
name: Test on Windows Server 2022
runs-on: windows-2022
steps:
- uses: compnerd/gha-setup-swift@main
with:
branch: swift-6.0-release
tag: 6.0-RELEASE
- uses: actions/checkout@v4
- name: Test
run: |
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true
swift test
65 changes: 1 addition & 64 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,60 +1,6 @@
{
"originHash" : "d2b30721124292e39b999beabef97a5a8e1680b0986e272531a064e85385927e",
"originHash" : "034e385c751c6af014263c63cdc6988fd6cd19e2b0a2e1bdd822f496ff903ad9",
"pins" : [
{
"identity" : "cwlcatchexception",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlCatchException.git",
"state" : {
"revision" : "07b2ba21d361c223e25e3c1e924288742923f08c",
"version" : "2.2.1"
}
},
{
"identity" : "cwlpreconditiontesting",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state" : {
"revision" : "0139c665ebb45e6a9fbdb68aabfd7c39f3fe0071",
"version" : "2.2.2"
}
},
{
"identity" : "nimble",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Quick/Nimble.git",
"state" : {
"revision" : "edaedc1ec86f14ac6e2ca495b94f0ff7150d98d0",
"version" : "12.3.0"
}
},
{
"identity" : "quick",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Quick/Quick.git",
"state" : {
"revision" : "1163a1b1b114a657c7432b63dd1f92ce99fe11a6",
"version" : "7.6.2"
}
},
{
"identity" : "swift-algorithms",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-algorithms.git",
"state" : {
"revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42",
"version" : "1.2.0"
}
},
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
"version" : "1.5.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
Expand All @@ -64,15 +10,6 @@
"version" : "1.1.4"
}
},
{
"identity" : "swift-numerics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-numerics.git",
"state" : {
"revision" : "0a5bc04095a675662cf24757cc0640aa2204253b",
"version" : "1.0.2"
}
},
{
"identity" : "swiftlintplugins",
"kind" : "remoteSourceControl",
Expand Down
4 changes: 1 addition & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ let package = Package(
targets: ["DependencyGraphs"])
],
dependencies: [
.package(url: "https://github.com/Quick/Quick.git", from: "7.0.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "12.0.0"),
.package(
url: "https://github.com/apple/swift-collections.git",
.upToNextMinor(from: "1.1.0")
Expand All @@ -32,7 +30,7 @@ let package = Package(
),
.testTarget(
name: "DependencyGraphsTests",
dependencies: ["DependencyGraphs", "Quick", "Nimble"]
dependencies: ["DependencyGraphs"]
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import Testing

@testable import DependencyGraphs

@Suite("C4 with vertices v1, v2, v3 and v4") struct C4ContainsVertexTests {
@Test("contains the vertex v1") func v1() {
#expect(TestGraph.directedC4().contains(vertex: vertex1) == true)
}

@Test("does not contain the vertex v5") func notV5() {
#expect(TestGraph.directedC4().contains(vertex: vertex5) == false)
}

@Test("contains the vertex v1' with v1' ≠ v1 and v1'.id = v1.id") func id1() {
let vertexWithId1 = Vertex(id: vertex1.id, label: "not 1")
#expect(TestGraph.directedC4().contains(vertex: vertexWithId1) == true)
}

@Test("does not contain the vertex v1' with v1' ≠ v1 and v1'.label = v1.label") func notLabel1() {
// C4 has only vertices with the ids 1, 2, 3 and 4.
let vertexWithLabel1 = Vertex(id: 5, label: "1")
#expect(TestGraph.directedC4().contains(vertex: vertexWithLabel1) == false)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Testing

@testable import DependencyGraphs

@Suite("C4 with vertices v1, v2, v3 and v4") struct C4ContainsVertexWithTests {
@Test("contains a vertex with an odd id") func oddId() {
#expect(
TestGraph.directedC4().contains(vertexWith: { vertexInGraph in
!vertexInGraph.id.isMultiple(of: 2)
}) == true
)
}

@Test("does not contain a vertex with an id that is divisible by 5") func notDivisibleBy5() {
#expect(
TestGraph.directedC4().contains(vertexWith: { vertexInGraph in
vertexInGraph.id.isMultiple(of: 5)
}) == false
)
}

@Test("contains a vertex with a label that starts with 3") func labelStartsWith3() {
#expect(
TestGraph.directedC4().contains(vertexWith: { vertexInGraph in
vertexInGraph.label.starts(with: "3")
}) == true
)
}

@Test("does not contain a vertex with a label that ends with .") func labelEndsWithDot() {
#expect(
TestGraph.directedC4().contains(vertexWith: { vertexInGraph in
vertexInGraph.label.hasSuffix(".")
}) == false
)
}
}
25 changes: 25 additions & 0 deletions Tests/SwiftDependencyGraphsTests/ContainsTests/EmptyGraph.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Testing

@testable import DependencyGraphs

@Suite("the empty graph") struct ContainsVertexWithTests {

@Test("does not contain the vertex v") func notVertexV() {
#expect(TestGraph.empty.contains(vertex: vertex1) == false)
}

@Test("does not contain a vertex with an even id") func notEvenId() {
#expect(
TestGraph.empty.contains(vertexWith: { vertexInGraph in vertexInGraph.id.isMultiple(of: 2)
}) == false
)
}

@Test("does not contain a vertex with a label that starts with a") func notLabelA() {
#expect(
TestGraph.empty.contains(vertexWith: { vertexInGraph in
vertexInGraph.label.starts(with: "a")
}) == false
)
}
}
91 changes: 0 additions & 91 deletions Tests/SwiftDependencyGraphsTests/ContainsVertexWithTests.swift

This file was deleted.

88 changes: 39 additions & 49 deletions Tests/SwiftDependencyGraphsTests/Dfs/Path.swift
Original file line number Diff line number Diff line change
@@ -1,58 +1,48 @@
import Nimble
import Quick
import Testing

@testable import DependencyGraphs

class DfsPathTests: QuickSpec {
override class func spec() {
describe("starting from vertex 1 in forwards direction") {
describe("visits all vertices") {
it("with the public method") {
expect(
TestGraph.path().depthFirstSearch(
startingFrom: vertex1, in: .forwards, reduceWith: appendReducer, withInitialValue: []
)
)
.to(equal([vertex1, vertex2, vertex3, vertex4, vertex5]))
}
@Suite("starting from vertex 1 in forwards direction") struct DfsPathTests {
@Suite("visits all vertices") struct VisitAllVerticesTests {
@Test("with the public method") func dfs() {
#expect(
TestGraph.path().depthFirstSearch(
startingFrom: vertex1, in: .forwards, reduceWith: appendReducer, withInitialValue: []
)
== [vertex1, vertex2, vertex3, vertex4, vertex5])
}

it("with the private method") {
expect(
TestGraph.path().depthFirstSearchImpl(
startingFrom: vertex1, in: .forwards, withVisited: [], reduceWith: appendReducer,
withInitialValue: [])
)
.to(equal([vertex1, vertex2, vertex3, vertex4, vertex5]))
}
}
@Test("with the private method") func dfsImpl() {
#expect(
TestGraph.path().depthFirstSearchImpl(
startingFrom: vertex1, in: .forwards, withVisited: [], reduceWith: appendReducer,
withInitialValue: [])
== [vertex1, vertex2, vertex3, vertex4, vertex5])
}
}

it("stops at 2 because 3 was already discovered") {
expect(
TestGraph.path().depthFirstSearchImpl(
startingFrom: vertex1, in: .forwards, withVisited: [vertex3],
reduceWith: appendReducer, withInitialValue: [])
)
.to(equal([vertex1, vertex2]))
}
@Test("stops at 2 because 3 was already discovered") func stops() {
#expect(
TestGraph.path().depthFirstSearchImpl(
startingFrom: vertex1, in: .forwards, withVisited: [vertex3],
reduceWith: appendReducer, withInitialValue: [])
== [vertex1, vertex2])
}

it("visits no vertices because all were already discovered") {
expect(
TestGraph.path().depthFirstSearchImpl(
startingFrom: vertex1, in: .forwards,
withVisited: [vertex1, vertex2, vertex3, vertex4, vertex5],
reduceWith: appendReducer, withInitialValue: emptyVertexList)
)
.to(equal([]))
}
@Test("visits no vertices because all were already discovered") func allDiscovered() {
#expect(
TestGraph.path().depthFirstSearchImpl(
startingFrom: vertex1, in: .forwards,
withVisited: [vertex1, vertex2, vertex3, vertex4, vertex5],
reduceWith: appendReducer, withInitialValue: emptyVertexList)
== [])
}

it("visits no vertices because 1 was already discovered") {
expect(
TestGraph.path().depthFirstSearchImpl(
startingFrom: vertex1, in: .forwards, withVisited: [vertex1],
reduceWith: appendReducer, withInitialValue: emptyVertexList)
)
.to(equal([]))
}
}
@Test("visits no vertices because 1 was already discovered") func nextDiscovered() {
#expect(
TestGraph.path().depthFirstSearchImpl(
startingFrom: vertex1, in: .forwards, withVisited: [vertex1],
reduceWith: appendReducer, withInitialValue: emptyVertexList)
== [])
}
}
Loading

0 comments on commit 06fd03e

Please sign in to comment.