From 3976694f60310a3aa537eaf1ce55504b193cfc7a Mon Sep 17 00:00:00 2001 From: Mario Lukas Mauberger Date: Wed, 17 May 2023 21:01:39 +0200 Subject: [PATCH] CATTY-453 Add missing tests for ArduinoDigitalPinFunction --- .../BluetoothMocks/BluetoothMocks.swift | 11 +++++++++++ .../Arduino/ArduinoAnalogPinFunctionTest.swift | 10 +++++++++- .../Arduino/ArduinoDigitalPinFunctionTest.swift | 10 +++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/CattyTests/BluetoothDevices/BluetoothMocks/BluetoothMocks.swift b/src/CattyTests/BluetoothDevices/BluetoothMocks/BluetoothMocks.swift index 9694fc43ce..8c8c28c50f 100644 --- a/src/CattyTests/BluetoothDevices/BluetoothMocks/BluetoothMocks.swift +++ b/src/CattyTests/BluetoothDevices/BluetoothMocks/BluetoothMocks.swift @@ -208,3 +208,14 @@ class ArduinoTestMock: ArduinoPropertyProtocol { internal let arduinoHelper = ArduinoHelper() } + +class ArduinoMock: ArduinoDevice { + + override func getDigitalArduinoPin(_ digitalPinNumber: Int) -> Double { + Double(digitalPinNumber) + } + + override func getAnalogPin(_ analogPinNumber: Int) -> Double { + Double(analogPinNumber) + } +} diff --git a/src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoAnalogPinFunctionTest.swift b/src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoAnalogPinFunctionTest.swift index a919ad43ec..1a65adc45d 100644 --- a/src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoAnalogPinFunctionTest.swift +++ b/src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoAnalogPinFunctionTest.swift @@ -20,6 +20,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ +import BluetoothHelper import XCTest @testable import Pocket_Code @@ -47,7 +48,14 @@ class ArduinoAnalogPinFunctionTest: XCTestCase { XCTAssertEqual(type(of: function).defaultValue, function.value(parameter: 0.5 as AnyObject), accuracy: Double.epsilon) } - // TODO: add testValue() test + func testValue() { + bluetoothService.arduino = ArduinoMock(peripheral: Peripheral(cbPeripheral: PeripheralMock.create(), advertisements: [String: String](), rssi: 0)) + + let expectedValue = 5 + let result = function.value(parameter: expectedValue as AnyObject) + bluetoothService.arduino = nil + XCTAssertEqual(Double(expectedValue), result) + } func testParameter() { XCTAssertEqual(.number(defaultValue: 0), function.firstParameter()) diff --git a/src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoDigitalPinFunctionTest.swift b/src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoDigitalPinFunctionTest.swift index e024ac6195..53a8bf825b 100644 --- a/src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoDigitalPinFunctionTest.swift +++ b/src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoDigitalPinFunctionTest.swift @@ -20,6 +20,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ +import BluetoothHelper import XCTest @testable import Pocket_Code @@ -47,7 +48,14 @@ class ArduinoDigitalPinFunctionTest: XCTestCase { XCTAssertEqual(type(of: function).defaultValue, function.value(parameter: 1.5 as AnyObject), accuracy: Double.epsilon) } - // TODO: add testValue() test + func testValue() { + bluetoothService.arduino = ArduinoMock(peripheral: Peripheral(cbPeripheral: PeripheralMock.create(), advertisements: [String: String](), rssi: 0)) + + let expectedValue = 5 + let result = function.value(parameter: expectedValue as AnyObject) + bluetoothService.arduino = nil + XCTAssertEqual(Double(expectedValue), result) + } func testParameter() { XCTAssertEqual(.number(defaultValue: 0), function.firstParameter())