Question

Correlated Active Clause Coverage (logic Coverage and JUnit) using the Logical Expression based method for developing...

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...

  1. Develop a suite of test cases to satisfy the Correlated Active Clause Coverage for the Thermostat class
  2. Would these test cases also meet the criteria for Restricted Active Clause Coverage? Explain why or why not.

Thermostat class

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Testing Files

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));
}
}


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));
}
}

Add a comment
Know the answer?
Add Answer to:
Correlated Active Clause Coverage (logic Coverage and JUnit) using the Logical Expression based method for developing...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • We have been learning about the Logical Expression based method for developing test coverage. In this...

    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. Develop a suite of test cases to satisfy the Predicate Coverage for the Thermostat class Example of a Test Case: P = (((A < B) ∨ (C ∧ A < D)) ∧...

  • This is my code for a TicTacToe game. However, I don't know how to write JUnit...

    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...

  • Java Help, Will definitely give a thumbs up if it works. Declare a class ComboLock that...

    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....

  • Hello, How would I test this in Junit? Is there anything else I can do with...

    Hello, How would I test this in Junit? Is there anything else I can do with my code? import java.text.DecimalFormat; public class PayCalculator implements Constants {       private String employeeName;    private int reportID;    private double hourlyWage;    private static int ID = 0;    private static int reportIDGenerator = 1000;    public int[] overtimes = HOURS_WORKED; public PayCalculator(String name) {    super(); {    this.reportID = reportIDGenerator;    reportIDGenerator+=10;    this.overtimes = HOURS_WORKED;    } } public...

  • Using a doubly linked list as the underlying data structure, implement a list ADT that implements...

    Using a doubly linked list as the underlying data structure, implement a list ADT that implements the ListInterface.java found in the ProgProjTwo Eclipse project starting point for this assignment. In addition to the forward iterator defined by resetIterator( ) and getNextItem( ) in ListInterface.java, implement a backwards iterator by providing resetBackIterator( ) and getPreviousItem( ) methods. As noted in the syllabus addendum, you are encouraged to develop a find( ) helper method that can support various list ADT operations. A...

  • software testing without making any changes to the java classes provided below, come up with some...

    software testing without making any changes to the java classes provided below, come up with some junit test cases to test the code. To get you started, here are four test cases you must implement: • Use the setString() function in MyCustomStringInterface to set the value to “H3y, l3t'5 put s0me d161ts in this 5tr1n6!11!!”. Then test to see if the CountNumbers() function is equal to the number of sequential digits in the original string (in this case, 9). •...

  • Registry Java Programming 2) Interface Comparator: The method for comparing two objects is written outside of...

    Registry Java Programming 2) Interface Comparator: The method for comparing two objects is written outside of the class of the objects to be sorted. Several methods can be written for comparing the objects according to different criteria. Specifically, write three classes, DescriptionComparator, FirstOccComparator, and LastOccComparator that implement the interface java.util.Comparator. DescriptionComparator implements the interface Comparator. The method compare compares the description of two objects. It returns a negative value if the description of the first object comes before the description...

  • Add another changeColor() method (i.e. you will now have 2 methods called "changeColor"). This one accepts...

    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...

    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...

  • Practically dying here with this, need help ASAP, just need to do hide(), hideBoth(), and matchFound(),...

    Practically dying here with this, need help ASAP, just need to do hide(), hideBoth(), and matchFound(), then implement them, so far in my version i tentatively made them, but I don't know ho to implement them so i posted the original code before i made my version of the three methods listed above. Need help fast, this is ridiculous. Implement just one requirement at a time. For example, try implementing the case where after the user clicks 2 squares, both...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT