|
| 1 | +classdef tCPT < mag.test.ViewControllerTestCase & matlab.uitest.TestCase |
| 2 | +% TCPT Unit tests for "mag.app.imap.control.CPT" class. |
| 3 | + |
| 4 | + properties (TestParameter) |
| 5 | + PatternField = {"PrimaryModePatternField", "SecondaryModePatternField", "RangePatternField"} |
| 6 | + end |
| 7 | + |
| 8 | + methods (Test) |
| 9 | + |
| 10 | + % Test that "instantiate" creates expected elements. |
| 11 | + function instantiate(testCase) |
| 12 | + |
| 13 | + % Set up. |
| 14 | + panel = testCase.createTestPanel(); |
| 15 | + cpt = mag.app.imap.control.CPT(); |
| 16 | + |
| 17 | + % Exercise. |
| 18 | + cpt.instantiate(panel); |
| 19 | + |
| 20 | + % Verify. |
| 21 | + testCase.assertNotEmpty(cpt.StartFilterSpinner, "Start filter spinner should not be empty."); |
| 22 | + testCase.assertNotEmpty(cpt.PrimaryModePatternField, "Primary mode pattern field should not be empty."); |
| 23 | + testCase.assertNotEmpty(cpt.SecondaryModePatternField, "Secondary mode pattern field should not be empty."); |
| 24 | + testCase.assertNotEmpty(cpt.RangePatternField, "Range pattern field should not be empty."); |
| 25 | + |
| 26 | + testCase.verifyEqual(cpt.StartFilterSpinner.Layout, matlab.ui.layout.GridLayoutOptions(Row = 1, Column = [2, 3]), ... |
| 27 | + "Start filter spinner layout should match expectation."); |
| 28 | + |
| 29 | + testCase.verifyEqual(cpt.PrimaryModePatternField.Value, '2, 64, 2, 4, 64, 4, 4, 128', "Primary mode pattern field value should match expectation."); |
| 30 | + testCase.verifyEqual(cpt.PrimaryModePatternField.Layout, matlab.ui.layout.GridLayoutOptions(Row = 2, Column = [2, 3]), ... |
| 31 | + "Primary mode pattern field layout should match expectation."); |
| 32 | + |
| 33 | + testCase.verifyEqual(cpt.SecondaryModePatternField.Value, '2, 8, 2, 1, 64, 1, 4, 128', "Secondary mode pattern field value should match expectation."); |
| 34 | + testCase.verifyEqual(cpt.SecondaryModePatternField.Layout, matlab.ui.layout.GridLayoutOptions(Row = 3, Column = [2, 3]), ... |
| 35 | + "Secondary mode pattern field layout should match expectation."); |
| 36 | + |
| 37 | + testCase.verifyEqual(cpt.RangePatternField.Value, '3, 2, 1, 0', "Range pattern field value should match expectation."); |
| 38 | + testCase.verifyEqual(cpt.RangePatternField.Layout, matlab.ui.layout.GridLayoutOptions(Row = 4, Column = [2, 3]), ... |
| 39 | + "Range pattern field layout should match expectation."); |
| 40 | + end |
| 41 | + |
| 42 | + % Test that "getVisualizeCommand" returns expected command. |
| 43 | + function getVisualizeCommand(testCase) |
| 44 | + |
| 45 | + % Set up. |
| 46 | + panel = testCase.createTestPanel(); |
| 47 | + |
| 48 | + cpt = mag.app.imap.control.CPT(); |
| 49 | + cpt.instantiate(panel); |
| 50 | + |
| 51 | + results = mag.imap.Analysis(); |
| 52 | + |
| 53 | + % Exercise. |
| 54 | + command = cpt.getVisualizeCommand(results); |
| 55 | + |
| 56 | + % Verify. |
| 57 | + testCase.verifyEqual(command.PositionalArguments, {results}, "Visualize command positional arguments should match expectation."); |
| 58 | + |
| 59 | + for f = ["Filter", "PrimaryModePattern", "SecondaryModePattern", "RangePattern"] |
| 60 | + testCase.assertThat(command.NamedArguments, mag.test.constraint.IsField(f), compose("""%s"" should be a named argument.", f)); |
| 61 | + end |
| 62 | + |
| 63 | + testCase.verifyEqual(command.NamedArguments.Filter, minutes(1), """Filter"" should match expectation."); |
| 64 | + testCase.verifyEqual(command.NamedArguments.PrimaryModePattern, [2, 64, 2, 4, 64, 4, 4, 128], """PrimaryModePattern"" should match expectation."); |
| 65 | + testCase.verifyEqual(command.NamedArguments.SecondaryModePattern, [2, 8, 2, 1, 64, 1, 4, 128], """SecondaryModePattern"" should match expectation."); |
| 66 | + testCase.verifyEqual(command.NamedArguments.RangePattern, [3, 2, 1, 0], """RangePattern"" should match expectation."); |
| 67 | + end |
| 68 | + |
| 69 | + % Test that error is thrown if patterns do not match expected |
| 70 | + % format. |
| 71 | + function pattern_validFormat(testCase, PatternField) |
| 72 | + |
| 73 | + % Set up. |
| 74 | + panel = testCase.createTestPanel(VisibleOverride = "on"); |
| 75 | + |
| 76 | + cpt = mag.app.imap.control.CPT(); |
| 77 | + cpt.instantiate(panel); |
| 78 | + |
| 79 | + % Exercise and verify. |
| 80 | + testCase.type(cpt.(PatternField), "1, 2, 3"); |
| 81 | + end |
| 82 | + |
| 83 | + % Test that alert is shown if patterns do not match expected |
| 84 | + % format. |
| 85 | + function pattern_invalidFormat(testCase, PatternField) |
| 86 | + |
| 87 | + % Set up. |
| 88 | + panel = testCase.createTestPanel(VisibleOverride = "on"); |
| 89 | + |
| 90 | + cpt = mag.app.imap.control.CPT(); |
| 91 | + cpt.instantiate(panel); |
| 92 | + |
| 93 | + % Exercise. |
| 94 | + testCase.type(cpt.(PatternField), "123 invalid"); |
| 95 | + |
| 96 | + % Verify. |
| 97 | + testCase.dismissDialog("uialert", panel.Parent); |
| 98 | + end |
| 99 | + end |
| 100 | +end |
0 commit comments