Skip to content

Commit

Permalink
feat(app): getMetroLineColor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krystxf committed May 15, 2024
1 parent 12987c0 commit 0cd11ef
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 38 deletions.
70 changes: 70 additions & 0 deletions app/metro-now/metro-now-tests/getMetroLineColorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// getMetroLineColorTests.swift
// metro-now-tests
//
// Created by Kryštof Krátký on 15.05.2024.
//

@testable import metro_now
import SwiftUI
import XCTest

final class getMetroLineColorTests: XCTestCase {
// MARK: - test if function returns correct color

/// should show positive and negative or zero seconds without any issues

func testGetMetroLineColorOutput() {
/// init variables for testing
var lineLetter: String
var result: Color
var expectedResult: Color

/// test 1
lineLetter = "A"
result = getMetroLineColor(lineLetter)
expectedResult = Color.green

XCTAssertEqual(result, expectedResult)

/// test 2
lineLetter = "B"
result = getMetroLineColor(lineLetter)
expectedResult = Color.yellow

XCTAssertEqual(result, expectedResult)

/// test 3
lineLetter = "C"
result = getMetroLineColor(lineLetter)
expectedResult = Color.red

XCTAssertEqual(result, expectedResult)

/// test 4
lineLetter = "a"
result = getMetroLineColor(lineLetter)
expectedResult = Color.green

XCTAssertEqual(result, expectedResult)

/// test 5
lineLetter = "b"
result = getMetroLineColor(lineLetter)
expectedResult = Color.yellow

XCTAssertEqual(result, expectedResult)

/// test 6
lineLetter = "c"
result = getMetroLineColor(lineLetter)
expectedResult = Color.red

XCTAssertEqual(result, expectedResult)

/// test 7
/// test if function throws an error
lineLetter = "other"
result = getMetroLineColor(lineLetter)
}
}
33 changes: 0 additions & 33 deletions app/metro-now/metro-now-tests/metro_now_tests.swift

This file was deleted.

8 changes: 4 additions & 4 deletions app/metro-now/metro-now.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
2DC63A0F2BF4D13200A72C7F /* stationsJSONManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC63A0E2BF4D13200A72C7F /* stationsJSONManager.swift */; };
2DC63A112BF4D3F800A72C7F /* stations.json in Resources */ = {isa = PBXBuildFile; fileRef = 2DC63A102BF4D3F800A72C7F /* stations.json */; };
2DC63A132BF4D98F00A72C7F /* getMetroLineColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC63A122BF4D98F00A72C7F /* getMetroLineColor.swift */; };
2DC63A1B2BF50E8F00A72C7F /* metro_now_tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC63A1A2BF50E8F00A72C7F /* metro_now_tests.swift */; };
2DC63A222BF50EDD00A72C7F /* formatTimeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC63A212BF50EDD00A72C7F /* formatTimeTests.swift */; };
2DC63A242BF5266700A72C7F /* getMetroLineColorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2DC63A232BF5266700A72C7F /* getMetroLineColorTests.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -54,8 +54,8 @@
2DC63A102BF4D3F800A72C7F /* stations.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = stations.json; path = ../../../../data/stations.json; sourceTree = "<group>"; };
2DC63A122BF4D98F00A72C7F /* getMetroLineColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = getMetroLineColor.swift; sourceTree = "<group>"; };
2DC63A182BF50E8F00A72C7F /* metro-now-tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "metro-now-tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
2DC63A1A2BF50E8F00A72C7F /* metro_now_tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = metro_now_tests.swift; sourceTree = "<group>"; };
2DC63A212BF50EDD00A72C7F /* formatTimeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = formatTimeTests.swift; sourceTree = "<group>"; };
2DC63A232BF5266700A72C7F /* getMetroLineColorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = getMetroLineColorTests.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -183,8 +183,8 @@
2DC63A192BF50E8F00A72C7F /* metro-now-tests */ = {
isa = PBXGroup;
children = (
2DC63A1A2BF50E8F00A72C7F /* metro_now_tests.swift */,
2DC63A212BF50EDD00A72C7F /* formatTimeTests.swift */,
2DC63A232BF5266700A72C7F /* getMetroLineColorTests.swift */,
);
path = "metro-now-tests";
sourceTree = "<group>";
Expand Down Expand Up @@ -309,7 +309,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2DC63A1B2BF50E8F00A72C7F /* metro_now_tests.swift in Sources */,
2DC63A242BF5266700A72C7F /* getMetroLineColorTests.swift in Sources */,
2DC63A222BF50EDD00A72C7F /* formatTimeTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 1 addition & 1 deletion app/metro-now/metro-now/Utils/getMetroLineColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import SwiftUI

func getMetroLineColor(_ letter: String) -> Color {
switch letter {
switch letter.uppercased() {
case "A":
.green
case "B":
Expand Down

0 comments on commit 0cd11ef

Please sign in to comment.