We have been learning about the Logical Expression based method for developing test coverage. In this assignment, we will use these techniques to discover and define test case information for the provided Thermostat class (and supplemental ProgrammedSettings, Period, and Daytime class), and convert them into JUnit/NUnit Test Cases.
|
P = (((A < B) ∨ (C ∧ A < D)) ∧ (E > F)) Predicate = TRUE: A = 5, B = 10, C = true, D = 10, E = 10, F = 5 (((5 < 10) ∨ (true ∧ 5 < 10)) ∧ (10 > 5)) (((True) ∨ (True ∧ True)) ∧ (True)) = True |
Thermostat.java
import java.io.*;
import java.time.Period;
import java.util.*;
// Programmable Thermostat
public class Thermostat
{
private int curTemp; // current temperature reading
private int thresholdDiff; // temp difference until we turn heater
on
private int timeSinceLastRun; // time since heater stopped
private int minLag; // how long I need to wait
private boolean override; // has user overridden the program
private int overTemp; // overriding temperature
private int runTime; // output of isEnergyEfficient - how long to
run
private boolean energyModeEnabled; // output of isEnergyEfficient -
whether to run
private Period period; // morning, day, evening, or night
private int day; // week day or weekend day
private boolean isHeating; // Whether the unit is currently heating
or not
public boolean isEnergyEfficient (ProgrammedSettings pSet)
{
int dTemp = pSet.getSetting (period, day);
if ( ( (!override && curTemp < overTemp -
thresholdDiff) ||
(curTemp < dTemp - thresholdDiff) )
&&
((timeSinceLastRun > minLag) ^ override) )
{ // Disable low energy mode to heat up the place
// How long? Assume 1 minute per degree (Fahrenheit)
int timeNeeded = curTemp - dTemp;
if (override)
{
timeNeeded = curTemp - overTemp;
}
setRunTime (timeNeeded);
enableEnergyMode (false);
return (true);
}
else
{
enableEnergyMode (true);
return (false);
}
}
public void setCurrentTemp (int temperature) { curTemp =
temperature; }
public void setThresholdDiff (int delta) { thresholdDiff = delta;
}
public void setTimeSinceLastRun (int minutes) { timeSinceLastRun =
minutes; }
public void setMinLag (int minutes) { minLag = minutes; }
public void setOverride (boolean value) { override = value; }
public void setOverTemp (int temperature) { overTemp = temperature;
}
public void setIsHeating (boolean value) { isHeating = value; }
// for the ProgrammedSettings
public void setDay (int curDay) { day = curDay; }
public void setPeriod (Period curPeriod) { period = curPeriod;
}
// outputs from isEnergyEfficient - need corresponding getters
to activate heater
void setRunTime (int minutes) { runTime = minutes; }
void enableEnergyMode (boolean value) { energyModeEnabled = value;
}
} // End Thermostat class
ProgrammedSettings.java
import java.time.Period;
//NOTE: Do not make predicates based on this class for Homework
4
public class ProgrammedSettings {
int temperature;
public ProgrammedSettings()
{
temperature = 76;
}
public ProgrammedSettings(int t)
{
temperature = t;
}
public int getSetting(Period p, int day)
{
return temperature;
}
}
Period.java
public enum Period
{
MORNING, DAY, EVENING, NIGHT
}
DayType.java
public enum DayType
{
WEEKDAY, WEEKEND
}
Answer:
CODE:
ThermostatPredicateCoverageTest.java
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class ThermostatPredicateCoverageTest {
private Thermostat thermostat;
private ProgrammedSettings programmedSettings;
@Before
public void Setup() {
thermostat = new Thermostat();
}
@Test
public void isEnergyEfficientTest1() {
programmedSettings = new ProgrammedSettings(35);
thermostat.setIsHeating(true);
thermostat.setOverride(false);
thermostat.setThresholdDiff(6);
assertTrue(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest2() {
programmedSettings = new ProgrammedSettings(70);
thermostat.setIsHeating(true);
thermostat.setOverride(false);
thermostat.setThresholdDiff(6);
assertTrue(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest3() {
programmedSettings = new ProgrammedSettings(90);
thermostat.setIsHeating(true);
thermostat.setOverride(false);
thermostat.setThresholdDiff(6);
assertFalse(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest4() {
programmedSettings = new ProgrammedSettings(70);
thermostat.setIsHeating(true);
thermostat.setOverride(true);
thermostat.setThresholdDiff(6);
assertFalse(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest5() {
programmedSettings = new ProgrammedSettings(70);
thermostat.setIsHeating(false);
thermostat.setOverride(false);
thermostat.setThresholdDiff(6);
assertTrue(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest6() {
programmedSettings = new ProgrammedSettings(40);
thermostat.setIsHeating(false);
thermostat.setOverride(true);
thermostat.setThresholdDiff(6);
assertTrue(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest7() {
programmedSettings = new ProgrammedSettings(40);
thermostat.setIsHeating(false);
thermostat.setOverride(false);
thermostat.setThresholdDiff(4);
assertTrue(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest8() {
programmedSettings = new ProgrammedSettings(40);
thermostat.setIsHeating(false);
thermostat.setOverride(true);
thermostat.setThresholdDiff(4);
assertFalse(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest9() {
programmedSettings = new ProgrammedSettings(40);
thermostat.setIsHeating(false);
thermostat.setOverride(false);
thermostat.setThresholdDiff(6);
assertFalse(thermostat.isEnergyEfficient(programmedSettings));
}
}
SCREENSHOTS OF THE CODE SHOWN BELOW:


ThermostatClauseCoverageTest.java
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class ThermostatClauseCoverageTest {
private Thermostat thermostat;
private ProgrammedSettings programmedSettings;
@Before
public void setUp() throws Exception {
thermostat = new Thermostat();
}
@Test
public void isEnergyEfficientTest1() {
programmedSettings = new ProgrammedSettings(35);
thermostat.setIsHeating(true);
thermostat.setOverride(false);
thermostat.setThresholdDiff(6);
thermostat.setCurrentTemp(40);
assertTrue(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest2() {
programmedSettings = new ProgrammedSettings(35);
thermostat.setIsHeating(true);
thermostat.setOverride(true);
thermostat.setThresholdDiff(6);
assertFalse(thermostat.isEnergyEfficient(programmedSettings));
}
@Test
public void isEnergyEfficientTest3() {
programmedSettings = new ProgrammedSettings(70);
thermostat.setIsHeating(false);
thermostat.setOverride(true);
thermostat.setThresholdDiff(6);
thermostat.setCurrentTemp(55);
assertFalse(thermostat.isEnergyEfficient(programmedSettings));
}
}
SCREENSHOT OF THE CODE SHOWN BELOW:

HOPE THIS MAY HELPS YOU.PLEASE GIVE POSITIVE RATINGS.THANKYOU...!!
We have been learning about the Logical Expression based method for developing test coverage. In this...
Correlated Active Clause Coverage (logic Coverage and JUnit) using the Logical Expression based method for developing test coverage, need help to discover and define test case information for the provided Thermostat class and convert them into JUnit Test Cases. Need help coming up with coming up Correlated Active Clause Coverage for the if statements in the thermostat class... Develop a suite of test cases to satisfy the Correlated Active Clause Coverage for the Thermostat class Would these test cases also...
In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show when my acceptbutton1 is pressed. One message is if the mouse HAS been dragged. One is if the mouse HAS NOT been dragged. /// I tried to make the Points class or the Mouse Dragged function return a boolean of true, so that I could construct an IF/THEN statement for the showDialog messages, but my boolean value was never accepted by ButtonHandler. *************************ButtonHandler class************************************...
[Java] We have learned the class Clock, which was designed to implement the time of day in a program. Certain application in addition to hours, minutes, and seconds might require you to store the time zone. Please do the following: Derive the class ExtClock from the class Clock by adding a data member to store the time zone. Add necessary methods and constructors to make the class functional. Also write the definitions of the methods and constructors. Write a test...
I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student { private String firstName; private String lastName; private String id; private boolean tuitionPaid; public Student(String firstName, String lastName, String id, boolean tuitionPaid) { this.firstName=firstName; this.lastName=lastName; this.id=id; this.tuitionPaid=tuitionPaid; } ...
Modify the library program as follows: Create a method in the LibraryMaterial class that accepts a string s as a parameter and returns true if the title of the string is equal to s. Create the same method for your library material copies. Note that it will need to be abstract in the LibraryMaterialCopy class MY CODE **************************************************************** LibraryCard: import java.util.List; import java.util.ArrayList; import java.time.LocalDate; import java.time.temporal.ChronoUnit; public class LibraryCard { private String id; private String cardholderName; ...
Java Help, Will definitely give a thumbs up if it works. Declare a class ComboLock that works like the combination lock in a gym locker (Consult the API provided to look for the methods needed). The locker is constructed with a combination - three numbers between 0 and 39. The reset method resets the dial so that it points to 0. The turnLeft and turnRight methods turn the dial by a given number of ticks to the left or right....
Add another changeColor() method (i.e. you will now have 2 methods called "changeColor"). This one accepts an int parameter and changes the color based on that int. The valid colors are "red", "yellow", "green", "blue", "magenta" and "black". In your code, map each color to an integer (e.g. in my code 3 means green.) If the number passed to the method is not valid, change the color to red. In the bounceTheBall() method, where you test for collisions with top...
This wont take you more than 15 mins. Comple the two method and besure to test with Junit test that provided below. toArray() -- this method returns a newly allocated array containing the elements in the multiset. The array this method returns must only contain the elements in the multiset and not any nulls or other values that are stored in the backing store, but are not in the multiset. fromArray(E[] arr) -- this method updates the multiset so that...
Write a Client class with a main method that tests the data structures as follows: For the ArrayStack, LinkedStack, ArrayQueue and LinkedQueue: Perform a timing test for each of these data structures. Each timing test should measure in nanoseconds how long it takes to add N Integers to the structure and how long it takes to remove N Integers from the structure. N should vary from 10 to 100,000,000 increasing N by a factor of 10 for each test. Depending...
This is my code for a TicTacToe game. However, I don't know how to write JUnit tests. Please help me with my JUnit Tests. I will post below what I have so far. package cs145TicTacToe; import java.util.Scanner; /** * A multiplayer Tic Tac Toe game */ public class TicTacToe { private char currentPlayer; private char[][] board; private char winner; /** * Default constructor * Initializes the board to be 3 by 3 and...