Skip to content

Commit 3976694

Browse files
CATTY-453 Add missing tests for ArduinoDigitalPinFunction
1 parent 9724bae commit 3976694

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

src/CattyTests/BluetoothDevices/BluetoothMocks/BluetoothMocks.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,14 @@ class ArduinoTestMock: ArduinoPropertyProtocol {
208208

209209
internal let arduinoHelper = ArduinoHelper()
210210
}
211+
212+
class ArduinoMock: ArduinoDevice {
213+
214+
override func getDigitalArduinoPin(_ digitalPinNumber: Int) -> Double {
215+
Double(digitalPinNumber)
216+
}
217+
218+
override func getAnalogPin(_ analogPinNumber: Int) -> Double {
219+
Double(analogPinNumber)
220+
}
221+
}

src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoAnalogPinFunctionTest.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* along with this program. If not, see http://www.gnu.org/licenses/.
2121
*/
2222

23+
import BluetoothHelper
2324
import XCTest
2425

2526
@testable import Pocket_Code
@@ -47,7 +48,14 @@ class ArduinoAnalogPinFunctionTest: XCTestCase {
4748
XCTAssertEqual(type(of: function).defaultValue, function.value(parameter: 0.5 as AnyObject), accuracy: Double.epsilon)
4849
}
4950

50-
// TODO: add testValue() test
51+
func testValue() {
52+
bluetoothService.arduino = ArduinoMock(peripheral: Peripheral(cbPeripheral: PeripheralMock.create(), advertisements: [String: String](), rssi: 0))
53+
54+
let expectedValue = 5
55+
let result = function.value(parameter: expectedValue as AnyObject)
56+
bluetoothService.arduino = nil
57+
XCTAssertEqual(Double(expectedValue), result)
58+
}
5159

5260
func testParameter() {
5361
XCTAssertEqual(.number(defaultValue: 0), function.firstParameter())

src/CattyTests/PlayerEngine/Functions/Arduino/ArduinoDigitalPinFunctionTest.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* along with this program. If not, see http://www.gnu.org/licenses/.
2121
*/
2222

23+
import BluetoothHelper
2324
import XCTest
2425

2526
@testable import Pocket_Code
@@ -47,7 +48,14 @@ class ArduinoDigitalPinFunctionTest: XCTestCase {
4748
XCTAssertEqual(type(of: function).defaultValue, function.value(parameter: 1.5 as AnyObject), accuracy: Double.epsilon)
4849
}
4950

50-
// TODO: add testValue() test
51+
func testValue() {
52+
bluetoothService.arduino = ArduinoMock(peripheral: Peripheral(cbPeripheral: PeripheralMock.create(), advertisements: [String: String](), rssi: 0))
53+
54+
let expectedValue = 5
55+
let result = function.value(parameter: expectedValue as AnyObject)
56+
bluetoothService.arduino = nil
57+
XCTAssertEqual(Double(expectedValue), result)
58+
}
5159

5260
func testParameter() {
5361
XCTAssertEqual(.number(defaultValue: 0), function.firstParameter())

0 commit comments

Comments
 (0)