Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the following interface for an ADT for representing intervals (periods

ID: 3906702 • Letter: C

Question

Consider the following interface for an ADT for representing intervals (periods of time as opposed to instantaneous moments of time) typedef long Duration; // measured in seconds class DateTime ( public DateTime (int year, int month, int day, int hour, int minute, int second): /Il How many seconds between two times? Duration operator-(const Date Time& right) const class Interval public: Il // An interval is a period of time beginning with a starting time /I and running up to, but not including, its stop time Interval 0: Interval (DateTime start, DateTime stop); Interval (DateTime start, Duration length): DateTime getStart) const: void setStart (DateTime); DateTime getStop) const void setStop (Date Time): Duration getDuration: bool contains (DateTime d) bool overlaps (Interval intrvl); bool operator (const Interval& other) const; private: DateTime theStart, theStop; Using the JUnit style, write a self-checking test for the 3rd Interval constuctor

Explanation / Answer

ANS.

JUnit test for the 3rd Interval constructor:-


import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class Interval3Test
{
private Interval expected;
@Before
public void setUp() throws Exception
{
DateTime dateTime = new DateTime(2018,6,21,12,0,0);
expected = new Interval(dateTime, getDuration());
}
@Test
public void test()
{
DateTime dateTime = new DateTime(2018,6,21,12,0,0);
Interval result = new Interval(dateTime, getDuration());
assertEquals(expected.toString(), result.toString());
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote