Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do i debug this/ import what needs to be imported? import org.junit.Assert; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import java.lang.reflect.*; public class GPACalculatorTest

How do i debug this/ import what needs to be imported?

import org.junit.Assert; import static org.junit.Assert.*; import org.junit.Before; import org.junit.Test; import java.lang.reflect.*;

public class GPACalculatorTest {

GPACalculator calc;

/** Fixture initialization (common initialization * for all tests). **/ @Before public void setUp() { calc = new GPACalculator(); }

/* Tests to make sure that the constructor is initializing the gpaTotal variable correctly. * If you are seeing -1 as your actual value, you either aren't initializing it at all, * or you changed the name of the variable */ @Test public void constructorTest1(){ double gpaTotal = -1; try{ /* Note that you do not need to understand how this test works. This is some * fancy stuff to get around the fact that these variables are private. You * should not try to do this outside of testing, as it defeats the purpose of * things being private */ Field gpaTotalField = GPACalculator.class.getDeclaredField("gpaTotal"); gpaTotalField.setAccessible(true); gpaTotal = (double)gpaTotalField.get(calc); } catch (Exception e){} // Message for the test Expected, Actual , Acceptable margin of error Assert.assertEquals("gpaTotal is initialized correctly by constructor", 0.0 , gpaTotal, 0.0); } /* Tests to make sure that the constructor is initializing the numCredits variable correctly. * If you are seeing -1 as your actual value, you either aren't initializing it at all, * or you changed the name of the variable */ @Test public void constructorTest2(){ int numCredits = -1; try{ /* Note that you do not need to understand how this test works. This is some * fancy stuff to get around the fact that these variables are private. You * should not try to do this outside of testing, as it defeats the purpose of * things being private */ Field numCreditsField = GPACalculator.class.getDeclaredField("numCredits"); numCreditsField.setAccessible(true); numCredits = (int)numCreditsField.get(calc); } catch (Exception e){} // Note that int assertions don't need an acceptable margin of error // Message for the test Expected, Actual Assert.assertEquals("gpaTotal is initialized correctly by constructor", 0 , numCredits); } /* Checks to make sure that getGPA() returns the correct value after the GPACalculator has been created */ @Test public void getGPATest1(){ Assert.assertEquals("getGPA returns the correct value of the GPA after initialization", 0.0, calc.getGPA(), 0.0); } /* Checks to make sure that getCredits() returns the correct value after the GPACalculator has been created */ @Test public void getCreditsTest1(){ Assert.assertEquals("getCredits returns the correct value of the GPA after initialization", 0, calc.getCredits()); } /* Checks to make sure that add() returns the correct GPA after it has been updated*/ @Test public void addTest1(){ double result = calc.addNewGradeToGPA(3.0, 4); Assert.assertEquals("add returns the correct GPA after it has been updated the first time", 3.0, result, 0.0); } /* Checks to make sure that add() returns the correct GPA after it has been updated repeatedly*/ @Test public void addTest2(){ calc.addNewGradeToGPA(3.0, 4); calc.addNewGradeToGPA(4.0, 4); double result = calc.addNewGradeToGPA(1.0, 4); double expected = (3.0*4+4.0*4+1.0*4)/(4+4+4); Assert.assertEquals("add returns the correct GPA after being updated multiple times", expected, result, 0.0001); } /* Checks to make sure that add() returns the correct GPA after it has been updated more complexly*/ @Test public void addTest3(){ calc.addNewGradeToGPA(3.0, 4); calc.addNewGradeToGPA(4.0, 2); double result = calc.addNewGradeToGPA(1.0, 0); double expected = (3.0*4+4.0*2+1.0*0)/(4+2+0); Assert.assertEquals("add returns the correct GPA after it has been updated in more complex ways", expected, result, 0.0001); } /* Checks to make sure getGPA continues to return correct GPA values after updates */ @Test public void getGPATest2(){ calc.addNewGradeToGPA(3.0, 4); calc.addNewGradeToGPA(4.0, 2); calc.addNewGradeToGPA(1.0, 0); double result = calc.getGPA(); double expected = (3.0*4+4.0*2+1.0*0)/(4+2+0); Assert.assertEquals("getGPA returns the correct GPA after it has been updated", expected, result, 0.0001); } /* Checks to make sure getCredits continues to return correct values after updates */ @Test public void getCreditsTest2(){ calc.addNewGradeToGPA(3.0, 4); calc.addNewGradeToGPA(4.0, 2); calc.addNewGradeToGPA(1.0, 0); int result = calc.getCredits(); int expected = 4+2+0; Assert.assertEquals("getCredits returns the correct number of total credits taken", expected, result); } /* Checks to make sure reset() resets GPA correctly */ @Test public void resetTest1(){ calc.addNewGradeToGPA(3.0, 4); calc.addNewGradeToGPA(4.0, 2); calc.addNewGradeToGPA(1.0, 15); calc.reset(); double result = calc.getGPA(); double expected = 0; Assert.assertEquals("reset correctly resets the total gpa", expected, result, 0); } /* Checks to make sure reset() resets credits correctly */ @Test public void resetTest2(){ calc.addNewGradeToGPA(3.0, 4); calc.addNewGradeToGPA(4.0, 2); calc.addNewGradeToGPA(1.0, 15); calc.reset(); int result = calc.getCredits(); int expected = 0; Assert.assertEquals("reset correctly resets the total gpa", expected, result); } } Errors:

----jGRASP exec: javac -g GPACalculatorTest.java GPACalculatorTest.java:1: error: package org.junit does not exist import org.junit.Assert; ^ GPACalculatorTest.java:2: error: package org.junit does not exist import static org.junit.Assert.*; ^ GPACalculatorTest.java:3: error: package org.junit does not exist import org.junit.Before; ^ GPACalculatorTest.java:4: error: package org.junit does not exist import org.junit.Test; ^ GPACalculatorTest.java:14: error: cannot find symbol @Before public void setUp() { ^ symbol: class Before location: class GPACalculatorTest GPACalculatorTest.java:22: error: cannot find symbol @Test public void constructorTest1(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:40: error: cannot find symbol @Test public void constructorTest2(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:57: error: cannot find symbol @Test public void getGPATest1(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:62: error: cannot find symbol @Test public void getCreditsTest1(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:67: error: cannot find symbol @Test public void addTest1(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:73: error: cannot find symbol @Test public void addTest2(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:82: error: cannot find symbol @Test public void addTest3(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:91: error: cannot find symbol @Test public void getGPATest2(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:101: error: cannot find symbol @Test public void getCreditsTest2(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:111: error: cannot find symbol @Test public void resetTest1(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:122: error: cannot find symbol @Test public void resetTest2(){ ^ symbol: class Test location: class GPACalculatorTest GPACalculatorTest.java:34: error: cannot find symbol Assert.assertEquals("gpaTotal is initialized correctly by constructor", 0.0 , gpaTotal, 0.0); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:53: error: cannot find symbol Assert.assertEquals("gpaTotal is initialized correctly by constructor", 0 , numCredits); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:58: error: cannot find symbol Assert.assertEquals("getGPA returns the correct value of the GPA after initialization", 0.0, calc.getGPA(), 0.0); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:63: error: cannot find symbol Assert.assertEquals("getCredits returns the correct value of the GPA after initialization", 0, calc.getCredits()); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:69: error: cannot find symbol Assert.assertEquals("add returns the correct GPA after it has been updated the first time", 3.0, result, 0.0); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:78: error: cannot find symbol Assert.assertEquals("add returns the correct GPA after being updated multiple times", expected, result, 0.0001); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:87: error: cannot find symbol Assert.assertEquals("add returns the correct GPA after it has been updated in more complex ways", expected, result, 0.0001); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:97: error: cannot find symbol Assert.assertEquals("getGPA returns the correct GPA after it has been updated", expected, result, 0.0001); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:107: error: cannot find symbol Assert.assertEquals("getCredits returns the correct number of total credits taken", expected, result); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:118: error: cannot find symbol Assert.assertEquals("reset correctly resets the total gpa", expected, result, 0); ^ symbol: variable Assert location: class GPACalculatorTest GPACalculatorTest.java:129: error: cannot find symbol Assert.assertEquals("reset correctly resets the total gpa", expected, result); ^ symbol: variable Assert location: class GPACalculatorTest 27 errors

----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

7. Identify four antecedents that influence intercultural contact.

Answered: 1 week ago

Question

5. Describe the relationship between history and identity.

Answered: 1 week ago