From 14d449cbd8b0f9ec8bfeac60503fe13939a5d369 Mon Sep 17 00:00:00 2001 From: Jeremy Huard Date: Mon, 9 Feb 2026 11:37:26 +0100 Subject: [PATCH] Added tests for LampView --- WorkshopGuide.md | 28 +++++++------- resources/project/Project.xml | 7 ++++ tests/tLampView.m | 72 +++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 14 deletions(-) create mode 100644 tests/tLampView.m diff --git a/WorkshopGuide.md b/WorkshopGuide.md index 30b1c3b..2292787 100644 --- a/WorkshopGuide.md +++ b/WorkshopGuide.md @@ -19,19 +19,19 @@ In this workshop, you will: ## Table of Contents  [Workshop Requirements](#H_34C2FB57) - [Part 1: Getting the workshop files and configuring GitHub for automated testing and results publishing](#TMP_877c) + [Part 1: Getting the workshop files and configuring GitHub for automated testing and results publishing](#TMP_3984) - [Part 2: Generating your first tests](#TMP_020d) + [Part 2: Generating your first tests](#TMP_95f4) - [Part 3: Finding existing tests and measuring coverage](#TMP_4b61) + [Part 3: Finding existing tests and measuring coverage](#TMP_8279) - [Part 4: Updating badges, committing our changes, and pushing to GitHub](#TMP_74db) + [Part 4: Updating badges, committing our changes, and pushing to GitHub](#TMP_1d39) - [Part 5: Create a pull request, watch GitHub Actions automatically test your changes and publish results](#TMP_651a) + [Part 5: Create a pull request, watch GitHub Actions automatically test your changes and publish results](#TMP_2a59) - [Part 6: Compile the App in the CI workflow and download the artifact](#TMP_85dd) + [Part 6: Compile the App in the CI workflow and download the artifact](#TMP_2c41) - [Workshop wrap\-up and additional information](#TMP_230e) + [Workshop wrap\-up and additional information](#TMP_86ec) @@ -56,7 +56,7 @@ The following steps cover all of the things you will need to successfully comple - The workshop leverages the free repository and CI capabilities offered by GitHub and GitHub Actions - Go to: [**https://github.com/signup**](https://github.com/signup) - + # Part 1: Getting the workshop files and configuring GitHub for automated testing and results publishing @@ -308,7 +308,7 @@ Click on the 'Run App' shortcut to start the app in MATLAB: ![image_20.png](WorkshopGuide_media/image_20.png) - + # Part 2: Generating your first tests @@ -529,7 +529,7 @@ Congratulations! You just created multiple tests for your MATLAB code! It was easier than you thought, right? - + # Part 3: Finding existing tests and measuring coverage @@ -868,7 +868,7 @@ It looks like we've achieved full statement coverage for [`generateSimFun`](./co ![image_65.png](WorkshopGuide_media/image_65.png) - + # Part 4: Updating badges, committing our changes, and pushing to GitHub @@ -1088,7 +1088,7 @@ At this point, all of your changes will be pushed to GitHub. ![image_85.png](WorkshopGuide_media/image_85.png) - + # Part 5: Create a pull request, watch GitHub Actions automatically test your changes and publish results @@ -1249,7 +1249,7 @@ The code coverage report looks like this: Now anyone that visits your repository can immediately see the quality of your code, explore your test and code coverage results, and will have more confidence in the code you are writing! - + # Part 6: Compile the App in the CI workflow and download the artifact @@ -1353,7 +1353,7 @@ You can now download the CTF file and upload it to your Web App Server using you [https://vdi\-wd1ah2\-348.dhcp.mathworks.com:9999/webapps/home/login.html](https://vdi-wd1ah2-348.dhcp.mathworks.com:9999/webapps/home/login.html) - + # Workshop wrap\-up and additional information diff --git a/resources/project/Project.xml b/resources/project/Project.xml index b4141a8..dfe1ea3 100644 --- a/resources/project/Project.xml +++ b/resources/project/Project.xml @@ -138,6 +138,13 @@ + + + + + + diff --git a/tests/tLampView.m b/tests/tLampView.m new file mode 100644 index 0000000..2e85a94 --- /dev/null +++ b/tests/tLampView.m @@ -0,0 +1,72 @@ +% This test file was generated by Copilot. Validate generated output before use. +classdef tLampView < matlab.unittest.TestCase + properties + Model + LampViewObj + Parent + end + + methods(TestMethodSetup) + function createLampView(testCase) + testCase.Parent = figure('Visible', 'off'); % Create a hidden figure for the lamp + testCase.Model = SimulationModel(); % Assuming SimulationModel is defined elsewhere + testCase.LampViewObj = LampView(testCase.Parent, testCase.Model); + end + end + + methods(Test) + function testIsOnTrue(testCase) + simulate(testCase.Model, [0.5234,0.0485,0.0934,119,150,24]); + + testCase.verifyTrue(testCase.LampViewObj.IsOn); + end + + function testIsOnFalse(testCase) + simulate(testCase.Model, [0.5234,0.0485,0.0934,119,200,24]); + + testCase.verifyFalse(testCase.LampViewObj.IsOn); + end + + function testLampColorSuccess(testCase) + testCase.LampViewObj.IsOn = true; + expectedColor = testCase.LampViewObj.LampColorSucess; + + actualColor = testCase.LampViewObj.LampObj.Color; + + testCase.verifyEqual(actualColor, expectedColor, 'Lamp color should be success color when IsOn is true.'); + end + + function testLampColorFailure(testCase) + testCase.LampViewObj.IsOn = false; + expectedColor = testCase.LampViewObj.LampColorFailure; + + actualColor = testCase.LampViewObj.LampObj.Color; + + testCase.verifyEqual(actualColor, expectedColor, 'Lamp color should be failure color when IsOn is false.'); + end + + function testTooltipSuccess(testCase) + testCase.LampViewObj.IsOn = true; + expectedTooltip = char(compose("Target occupancy remains\n between thresholds")); + + actualTooltip = testCase.LampViewObj.LampObj.Tooltip; + + testCase.verifyEqual(actualTooltip, expectedTooltip, 'Tooltip should indicate success when IsOn is true.'); + end + + function testTooltipFailure(testCase) + testCase.LampViewObj.IsOn = false; + expectedTooltip = char(compose("Target occupancy does not remain\n between thresholds")); + + actualTooltip = testCase.LampViewObj.LampObj.Tooltip; + + testCase.verifyEqual(actualTooltip, expectedTooltip, 'Tooltip should indicate failure when IsOn is false.'); + end + end + + methods(TestMethodTeardown) + function closeFigure(testCase) + close(testCase.Parent); + end + end +end \ No newline at end of file