Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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