diff options
| author | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-09 08:43:04 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <git@r.bdr.sh> | 2025-07-09 08:43:04 +0200 |
| commit | 1e89ea22d551cebfd6c0c0451000c3283ddb2d2e (patch) | |
| tree | 77afac88484877fbea5fecd1ddda85741584c6c5 /MapTests | |
| parent | 1ec7f2c6deb64f5b13b32fae2bf74ae2d8aaaabb (diff) | |
Get rid of old map parser
Diffstat (limited to 'MapTests')
| -rw-r--r-- | MapTests/MapParserStrategyTests.swift | 163 | ||||
| -rw-r--r-- | MapTests/MapTests.swift | 169 |
2 files changed, 0 insertions, 332 deletions
diff --git a/MapTests/MapParserStrategyTests.swift b/MapTests/MapParserStrategyTests.swift deleted file mode 100644 index 7061d4d..0000000 --- a/MapTests/MapParserStrategyTests.swift +++ /dev/null @@ -1,163 +0,0 @@ -// Copyright (C) 2024 Rubén Beltrán del Río - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -import CoreGraphics -// You should have received a copy of the GNU General Public License -// along with this program. If not, see https://map.tranquil.systems. -import Testing - -@testable import Map - -struct MapParserStrategyTests { - - @Test func testVertexParserStrategyCanHandle() async throws { - let strategy = VertexParserStrategy() - - #expect(strategy.canHandle(line: "Node (10, 20)")) - #expect(strategy.canHandle(line: "NodeWithDecimals (30.5, 40.2)")) - #expect(strategy.canHandle(line: "Multi Word Node (0, 100)")) - #expect(strategy.canHandle(line: "Node C (50, 60) [square]")) - - #expect(!strategy.canHandle(line: "Node A -> Node B")) - #expect(!strategy.canHandle(line: "[Note] (10, 20) Test")) - #expect(!strategy.canHandle(line: "Invalid line")) - } - - @Test func testVertexParserStrategyHandle() async throws { - let strategy = VertexParserStrategy() - let vertices: [String: Vertex] = [:] - - let (type, object) = strategy.handle(index: 0, line: "Test Node (25, 75)", vertices: vertices) - - #expect(String(describing: type) == String(describing: Vertex.self)) - let vertex = object as! Vertex - #expect(vertex.id == 0) - #expect(vertex.label == "Test Node") - #expect(vertex.position.x == 25.0) - #expect(vertex.position.y == 75.0) - #expect(vertex.shape == .circle) - } - - @Test func testVertexParserStrategyHandleWithShape() async throws { - let strategy = VertexParserStrategy() - let vertices: [String: Vertex] = [:] - - let (type, object) = strategy.handle( - index: 1, line: "Shaped Node (10, 20) [triangle]", vertices: vertices) - - #expect(String(describing: type) == String(describing: Vertex.self)) - let vertex = object as! Vertex - #expect(vertex.shape == .triangle) - } - - @Test func testEdgeParserStrategyCanHandle() async throws { - let strategy = EdgeParserStrategy() - - #expect(strategy.canHandle(line: "Node A -- Node B")) - #expect(strategy.canHandle(line: "Node A -> Node B")) - #expect(strategy.canHandle(line: "Multi Word A -> Multi Word B")) - - #expect(!strategy.canHandle(line: "Node A (10, 20)")) - #expect(!strategy.canHandle(line: "[Note] (10, 20) Test")) - #expect(!strategy.canHandle(line: "Invalid line")) - } - - @Test func testEdgeParserStrategyHandle() async throws { - let strategy = EdgeParserStrategy() - let vertices: [String: Vertex] = [ - "Node A": Vertex(id: 0, label: "Node A", position: CGPoint(x: 10, y: 20)), - "Node B": Vertex(id: 1, label: "Node B", position: CGPoint(x: 30, y: 40)), - ] - - let (type, object) = strategy.handle(index: 2, line: "Node A -> Node B", vertices: vertices) - - #expect(String(describing: type) == String(describing: MapEdge.self)) - let edge = object as! MapEdge - #expect(edge.id == 2) - #expect(edge.origin.x == 10.0) - #expect(edge.origin.y == 20.0) - #expect(edge.destination.x == 30.0) - #expect(edge.destination.y == 40.0) - #expect(edge.arrowhead == true) - } - - @Test func testEdgeParserStrategyHandleWithMissingVertex() async throws { - let strategy = EdgeParserStrategy() - let vertices: [String: Vertex] = [ - "Node A": Vertex(id: 0, label: "Node A", position: CGPoint(x: 10, y: 20)) - ] - - let (type, object) = strategy.handle(index: 2, line: "Node A -> Node B", vertices: vertices) - - #expect(String(describing: type) == String(describing: NSObject.self)) - #expect(object is NSObject) - } - - @Test func testNoteParserStrategyCanHandle() async throws { - let strategy = NoteParserStrategy() - - #expect(strategy.canHandle(line: "[Note] (10, 20) Test note")) - #expect(strategy.canHandle(line: "[Note] (50.5, 60.2) Multi word note")) - - #expect(!strategy.canHandle(line: "Node A (10, 20)")) - #expect(!strategy.canHandle(line: "Node A -> Node B")) - #expect(!strategy.canHandle(line: "Invalid line")) - } - - @Test func testInertiaParserStrategyCanHandle() async throws { - let strategy = InertiaParserStrategy() - - #expect(strategy.canHandle(line: "[Indertia] Node A")) - #expect(strategy.canHandle(line: "[Inertia] Multi Word Node")) - - #expect(!strategy.canHandle(line: "Node A (10, 20)")) - #expect(!strategy.canHandle(line: "[Note] (10, 20) Test")) - #expect(!strategy.canHandle(line: "Invalid line")) - } - - @Test func testOpportunityParserStrategyCanHandle() async throws { - let strategy = OpportunityParserStrategy() - - #expect(strategy.canHandle(line: "[Evolution] Node A +15")) - #expect(strategy.canHandle(line: "[Evolution] Node B -10")) - #expect(strategy.canHandle(line: "[Evolution] Multi Word Node +5.5")) - - #expect(!strategy.canHandle(line: "Node A (10, 20)")) - #expect(!strategy.canHandle(line: "[Inertia] Node A")) - #expect(!strategy.canHandle(line: "Invalid line")) - } - - @Test func testStageParserStrategyCanHandle() async throws { - let strategy = StageParserStrategy() - - #expect(strategy.canHandle(line: "[I] 25")) - #expect(strategy.canHandle(line: "[II] 50.5")) - #expect(strategy.canHandle(line: "[III] 75")) - - #expect(!strategy.canHandle(line: "[IV] 100")) - #expect(!strategy.canHandle(line: "Node A (10, 20)")) - #expect(!strategy.canHandle(line: "Invalid line")) - } - - @Test func testGroupParserStrategyCanHandle() async throws { - let strategy = GroupParserStrategy() - - #expect(strategy.canHandle(line: "[Group] Node A, Node B")) - #expect(strategy.canHandle(line: "[Group] Node A, Node B, Node C")) - #expect(strategy.canHandle(line: "[Group] Multi Word A, Multi Word B")) - - #expect(!strategy.canHandle(line: "Node A (10, 20)")) - #expect(!strategy.canHandle(line: "[Note] (10, 20) Test")) - #expect(!strategy.canHandle(line: "Invalid line")) - } - -} diff --git a/MapTests/MapTests.swift b/MapTests/MapTests.swift deleted file mode 100644 index fd092d0..0000000 --- a/MapTests/MapTests.swift +++ /dev/null @@ -1,169 +0,0 @@ -import CoreGraphics -import Testing - -@testable import Map - -struct MapTests { - - @Test func testMapParserWithEmptyInput() async throws { - let result = MapParser.parse(content: "") - #expect(result.vertices.isEmpty) - #expect(result.edges.isEmpty) - #expect(result.notes.isEmpty) - #expect(result.inertias.isEmpty) - #expect(result.opportunities.isEmpty) - #expect(result.groups.isEmpty) - } - - @Test func testMapParserWithSingleVertex() async throws { - let content = "Node A (10, 20)" - let result = MapParser.parse(content: content) - - #expect(result.vertices.count == 1) - let vertex = result.vertices.first! - #expect(vertex.label == "Node A") - #expect(vertex.position.x == 10.0) - #expect(vertex.position.y == 20.0) - #expect(vertex.shape == .circle) - } - - @Test func testMapParserWithVertexWithShape() async throws { - let content = "Node B (30, 40) [square]" - let result = MapParser.parse(content: content) - - #expect(result.vertices.count == 1) - let vertex = result.vertices.first! - #expect(vertex.label == "Node B") - #expect(vertex.position.x == 30.0) - #expect(vertex.position.y == 40.0) - #expect(vertex.shape == .square) - } - - @Test func testMapParserWithEdge() async throws { - let content = """ - Node A (10, 20) - Node B (30, 40) - Node A -- Node B - """ - let result = MapParser.parse(content: content) - - #expect(result.vertices.count == 2) - #expect(result.edges.count == 1) - let edge = result.edges.first! - #expect(edge.origin.x == 10.0) - #expect(edge.origin.y == 20.0) - #expect(edge.destination.x == 30.0) - #expect(edge.destination.y == 40.0) - #expect(edge.arrowhead == false) - } - - @Test func testMapParserWithArrowEdge() async throws { - let content = """ - Node A (10, 20) - Node B (30, 40) - Node A -> Node B - """ - let result = MapParser.parse(content: content) - - #expect(result.edges.count == 1) - let edge = result.edges.first! - #expect(edge.arrowhead == true) - } - - @Test func testMapParserWithNote() async throws { - let content = "[Note] (50, 60) This is a test note" - let result = MapParser.parse(content: content) - - #expect(result.notes.count == 1) - let note = result.notes.first! - #expect(note.position.x == 50.0) - #expect(note.position.y == 60.0) - #expect(note.text == "This is a test note") - } - - @Test func testMapParserWithInertia() async throws { - let content = """ - Node A (10, 20) - [Inertia] Node A - """ - let result = MapParser.parse(content: content) - - #expect(result.inertias.count == 1) - let inertia = result.inertias.first! - #expect(inertia.position.x == 10.0) - #expect(inertia.position.y == 20.0) - } - - @Test func testMapParserWithOpportunity() async throws { - let content = """ - Node A (10, 20) - [Evolution] Node A +15 - """ - let result = MapParser.parse(content: content) - - #expect(result.opportunities.count == 1) - let opportunity = result.opportunities.first! - #expect(opportunity.origin.x == 10.0) - #expect(opportunity.origin.y == 20.0) - #expect(opportunity.destination.x == 25.0) - #expect(opportunity.destination.y == 20.0) - } - - @Test func testMapParserWithGroup() async throws { - let content = """ - Node A (10, 20) - Node B (30, 40) - Node C (50, 60) - [Group] Node A, Node B, Node C - """ - let result = MapParser.parse(content: content) - - #expect(result.groups.count == 1) - let group = result.groups.first! - #expect(group.count == 3) - #expect(group.map { $0.label }.contains("Node A")) - #expect(group.map { $0.label }.contains("Node B")) - #expect(group.map { $0.label }.contains("Node C")) - } - - @Test func testMapParserWithStages() async throws { - let content = """ - [I] 15 - [II] 35 - [III] 80 - """ - let result = MapParser.parse(content: content) - - #expect(result.stages.count == 3) - #expect(result.stages[0] == 15.0) - #expect(result.stages[1] == 35.0) - #expect(result.stages[2] == 80.0) - } - - @Test func testMapParserWithComplexMap() async throws { - let content = """ - Node A (10, 20) - Node B (30, 40) [square] - Node C (50, 60) - Node A -> Node B - Node B -- Node C - [Note] (70, 80) Complex map example - [Inertia] Node A - [Evolution] Node B +10 - [Group] Node A, Node C - [I] 25 - [II] 75 - """ - let result = MapParser.parse(content: content) - - #expect(result.vertices.count == 3) - #expect(result.edges.count == 2) - #expect(result.notes.count == 1) - #expect(result.inertias.count == 1) - #expect(result.opportunities.count == 1) - #expect(result.groups.count == 1) - #expect(result.stages[0] == 25.0) - #expect(result.stages[1] == 75.0) - } - -} |