From 3acf4e9ac5dc0a2eb99a0d60554bed141d2c6c91 Mon Sep 17 00:00:00 2001 From: Caitlin Hennessy Date: Tue, 19 Dec 2017 14:55:48 -0800 Subject: [PATCH] More hardware tests (#119) --- tests/colors.ts | 35 +++++++++++++++++++++++++++++++++++ tests/touch.ts | 7 +++++++ tests/ultrasonic.ts | 9 +++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/colors.ts create mode 100644 tests/touch.ts create mode 100644 tests/ultrasonic.ts diff --git a/tests/colors.ts b/tests/colors.ts new file mode 100644 index 00000000..15d6d02f --- /dev/null +++ b/tests/colors.ts @@ -0,0 +1,35 @@ +tests.test("Detect color red", function () { + brick.print("Point sensor to red", 0, 50) + brick.print("and click enter", 0, 60) + brick.buttonEnter.pauseUntil(ButtonEvent.Click) + brick.clearScreen() + let actualColor = sensors.color1.color() + tests.assertClose("Color", actualColor, ColorSensorColor.Red, 0) +}) + +tests.test("Bright ambient light", function () { + brick.print("Point sensor to ceiling", 0, 50) + brick.print("light and click enter", 0, 60) + brick.buttonEnter.pauseUntil(ButtonEvent.Click) + brick.clearScreen() + let actualLight: number + for (let i = 0; i < 4; i++) { + actualLight = sensors.color1.ambientLight() + loops.pause(500) + } + tests.assertClose("Light", actualLight, 20, 15) +}) + +tests.test("Bright reflected light", function () { + brick.print("Point sensor to white", 0, 50) + brick.print("desk surface", 0, 60) + brick.print("and click enter", 0, 70) + brick.buttonEnter.pauseUntil(ButtonEvent.Click) + brick.clearScreen() + let actualLight: number + for (let i = 0; i < 4; i++) { + actualLight = sensors.color1.reflectedLight() + loops.pause(500) + } + tests.assertClose("Light", actualLight, 17, 14) +}) \ No newline at end of file diff --git a/tests/touch.ts b/tests/touch.ts new file mode 100644 index 00000000..b3a432d8 --- /dev/null +++ b/tests/touch.ts @@ -0,0 +1,7 @@ +tests.test("Touch sensor pressed", function () { + brick.print("Press touch sensor", 0, 50) + brick.print("and click enter", 0, 60) + brick.buttonEnter.pauseUntil(ButtonEvent.Click) + brick.clearScreen() + tests.assert("Pressed", sensors.touchSensor1.isPressed()) +}) \ No newline at end of file diff --git a/tests/ultrasonic.ts b/tests/ultrasonic.ts new file mode 100644 index 00000000..f431496b --- /dev/null +++ b/tests/ultrasonic.ts @@ -0,0 +1,9 @@ +tests.test("Ultrasonic sensor", function () { + brick.print("Place object ", 0, 50) + brick.print("one finger's length", 0, 60) + brick.print("in front of sensor", 0, 70) + brick.print("and click enter", 0, 80) + brick.buttonEnter.pauseUntil(ButtonEvent.Click) + brick.clearScreen() + tests.assertClose("Distance", sensors.ultrasonic1.distance(), 7, 6) +}) \ No newline at end of file