Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/Average.class
Binary file not shown.
27 changes: 27 additions & 0 deletions src/Average.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Average {
private int count = 0;
private double sum = 0;
public Average() {

}

public void addValue(double value) {
sum += value;
count ++;
}

public double getAverage() {
if (count == 0) {
return 0;
}
else {
return (double)sum/count;
}
}

public int getCount() {
return count;
}
}


27 changes: 27 additions & 0 deletions src/Average.java~
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
public class Average {
private int count = 0;
private double sum = 0;
public Average() {

}

public void addValue(double value) {
sum += value;
count += 1;
}

public double getAverage() {
if (count == 0) {
return 0;
}
else {
return sum/count;
}
}

public int getCount() {
return count;
}
}


Binary file added src/AverageTest.class
Binary file not shown.
50 changes: 50 additions & 0 deletions src/AverageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import junit.framework.TestCase;

public class AverageTest extends TestCase {

public void testNewAverage() {
{
Average avg = new Average();

assertEquals(0, avg.getCount());
assertEquals(0, avg.getAverage(), 0.001);
}
}
public void testSingleValue()
{
Average avg = new Average();
avg.addValue(5.5);
assertEquals(5.5, avg.getAverage(), 0.001);
assertEquals(1, avg.getCount());
}
public void testValueNotZero(){
Average avg = new Average();
avg.addValue(5.0);
avg.addValue(5.0);
avg.addValue(5.0);
avg.addValue(5.0);
avg.addValue(5.0);
assertEquals(5.0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
public void testValueIsZero(){
Average avg = new Average();
avg.addValue(2.0);
avg.addValue(-2.0);
avg.addValue(1.0);
avg.addValue(-1.0);
avg.addValue(0.0);
assertEquals(0.0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
public void testSameValue(){
Average avg = new Average();
avg.addValue(1.1);
avg.addValue(1.1);
avg.addValue(1.1);
avg.addValue(1.1);
avg.addValue(1.1);
assertEquals(1.1, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
}
60 changes: 60 additions & 0 deletions src/AverageTest.java~
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import junit.framework.TestCase;


public class AverageTest extends TestCase {
public void testNewAverage() {
Average avg = new Average();

assertEquals(0, avg.getCount());

assertEquals(0, avg.getAverage(), 0.001);

}
public void testSingleValue() {
Average avg = new Average();

avg.addValue(5.5);

assertEquals(5.5, avg.getAverage(), 0.001);
assertEquals(1, avg.getCount());
}
public void testFiveValuesNonZeroAverage() {
Average avg = new Average ();
avg.addValue(10.0);
avg.addValue(9.5);
avg.addValue(3.0);
avg.addValue(4.0);
avg.addValue(6.0);


assertEquals(6.5, avg.getAverage(), 0.001);

assertEquals(5, avg.getCount());
}
public void testFiveValuesZeroAverage() {
Average avg = new Average ();
avg.addValue(-1);
avg.addValue(0);
avg.addValue(-2);
avg.addValue(1);
avg.addValue(2);


assertEquals(0, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}
public void testFiveValuesSameAverage() {
Average avg = new Average ();
avg.addValue(100);
avg.addValue(100);
avg.addValue(100);
avg.addValue(100);
avg.addValue(100);


assertEquals(100, avg.getAverage(), 0.001);
assertEquals(5, avg.getCount());
}

}

Binary file added src/Range.class
Binary file not shown.
62 changes: 62 additions & 0 deletions src/Range.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
public class Range {
private double start;
private double stop;

public Range(double start, double stop) {
if (start <= stop) {
this.start = start;
this.stop = stop;
}
else {
this.start = stop;
this.stop = start;
}

}

public boolean contains(double value) {
if ((value >= start) && (value < stop)) {
return true;
}
return false;


}

public double getWidth() {
return stop-start;

}

public double getMin() {
return start;

}

public double getMax() {
return stop;
}

public Range intersection(Range other) {
double newMin = 0;
double newMax = 0;
if (other.contains(start)) {
newMin = start;
}

if (other.contains(stop)) {
newMax = stop;
}

if (contains(other.getMin())) {
newMin = other.getMin();
}

if (contains(other.getMax())) {
newMax = other.getMax();
}


return new Range(newMin, newMax);
}
}
44 changes: 44 additions & 0 deletions src/Range.java~
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
public class Range {
public Range(double start, double stop) {
{
if (start > stop)
{
max = start;
min = stop;
}

if (stop > start)
{
max = stop;
min = start;
}

if (stop == start)
{
min = 0;
max = 0;
}
}


public boolean contains (double value) {
return true;
}

public double getWidth () {
return 0.0;
}

public double getMin() {
return 0.0;
}
public double getMax() {
return 0.0;
}
public Range intersection(Range other) {
return new Range(0.0, 0.0);
}
}



Binary file added src/RangeTest.class
Binary file not shown.
15 changes: 15 additions & 0 deletions src/RangeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import junit.framework.TestCase;


public class RangeTest extends TestCase {
public void testNewRange() {
Range rng = new Range(0.0, 0.0);
}
public void testMin() {
Range r1 = new Range(1.0, 10.0);
assertEquals(1.0, r1.getMin(), 0.001);
Range r2 = new Range(5.0, -1.0);
assertEquals(-1.0, r2.getMin(),0.001);
}
}

10 changes: 10 additions & 0 deletions src/RangeTest.java~
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import junit.framework.TestCase;


public class Range test extends TestCase {
public void testX() {
Range rng = new Range(0.0, 0.0):
}
public void testMin() {
}

25 changes: 25 additions & 0 deletions src/Testing Lab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# CSCI 121: Lab #4
## Testing Lab
### 2/12/15
##### Marlon Moraga


#Question 1:
** The first mistake that many developers can make is trying to fit two or more data types into an array. For example, putting an integer and a string together in the same array. Another mistakes is forgettin to order the scores from greatest to elast in the array. Usually in a array they tend to want everything organized. Lastly, the third problem could be that one will be using parellel rays instead of an object to record the scores and names.**







#Question 2:

**If a new scoreboard were to be created, then it would simply be a scoreboard with no values in it. If a single mutation were to occur to the scoreboard, then the scoreboard would be a scoreboard with one value and one name in it. If multiple mutations were to occur then the scoreboard would have multiple scores**

#Question 3:
1. The instance would be empty with no values because they haven't been assigned to anything yet.

2. There isn't really a simple mutation possible for this class at this point.

3.There are no boundary conditions, currently it is laced at 0 for testing.