Skip to content

Commit

Permalink
CATTY-453 Add missing tests for ArduinoDigitalPinFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
mariomauberger committed May 19, 2023
1 parent 9724bae commit 3976694
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

import BluetoothHelper
import XCTest

@testable import Pocket_Code
Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* along with this program. If not, see http://www.gnu.org/licenses/.
*/

import BluetoothHelper
import XCTest

@testable import Pocket_Code
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 3976694

Please sign in to comment.