Commit 584e22da authored by Anya Helene Bagge's avatar Anya Helene Bagge 🦆

stuff from f07

parent 74252292
......@@ -2,12 +2,16 @@ package inf101.tests;
import static org.junit.Assert.fail;
import java.util.Random;
import static org.junit.Assert.assertEquals;
import inf101.util.IGenerator;
import inf101.util.generators.IntGenerator;
import inf101.util.generators.MyListGenerator;
import inf101.util.generators.StringGenerator;
import inf101.v16.datastructures.IList;
import inf101.v16.datastructures.MyList;
import inf101.v16.datastructures.Range;
import org.junit.Test;
......@@ -15,7 +19,9 @@ public class MyListTest {
private static final int N = 10000;
private IGenerator<String> strGen = new StringGenerator();
private IGenerator<IList<String>> listGen = new MyListGenerator<String>(strGen);
private IGenerator<Integer> intGen = new IntGenerator();
private IGenerator<IList<String>> listGen = new MyListGenerator<>(strGen);
private IGenerator<IList<Integer>> intListGen = new MyListGenerator<>(intGen);
/**
* all cells are equals to val, after grid.clear(val)
......@@ -78,6 +84,21 @@ public class MyListTest {
assertEquals(val, list.get(a));
}
@Test
public void setGetTest0() {
Random random = new Random();
for (int i : new Range(0, 100000)) {
IList<Integer> list = intListGen.generate();
if (list.size() > 0) {
int index = random.nextInt(list.size());
int elem = intGen.generate();
setGetProperty(list, index, elem);
}
}
}
/**
* Test that get gives back the same value after set.
*/
......@@ -105,14 +126,12 @@ public class MyListTest {
private <T> void iteratorProperty(IList<T> list) {
// TODO: lag en egenskap som bruker "forbedret for-løkke" til å gå
// gjennom
// alle elementene i list, og sjekke at de kommer i samme rekkefølge som
// om man
// kaller get på indeksene 0 .. list.size()
fail("Not implemented");
int i = 0;
for (T obj : list) {
assertEquals(list.get(i), obj);
i = i + 1;
}
// TODO: husk å sjekke at løkken har gått gjennom alle elementene i
// listen
assertEquals(list.size(), i);
}
}
......@@ -68,7 +68,20 @@ public class MyList<T> implements IList<T> {
@Override
public Iterator<T> iterator() {
return null; // TODO: lag en iterator
return new Iterator<T>() {
int i = 0;
@Override
public boolean hasNext() {
return i < size();
}
@Override
public T next() {
return get(i++);
}
};
}
}
......@@ -3,21 +3,6 @@ package inf101.v16.datastructures;
import java.util.Iterator;
public class Range implements Iterable<Integer>, IRange{
private final class RangeIterator implements Iterator<Integer> {
int teller = low;
@Override
public boolean hasNext() {
return teller < high;
}
@Override
public Integer next() {
return teller++;
}
}
private int low;
private int high;
......@@ -29,6 +14,25 @@ public class Range implements Iterable<Integer>, IRange{
this.high = high;
}
@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {
int teller = low;
@Override
public boolean hasNext() {
return teller < high; // TODO
}
@Override
public Integer next() {
int tall = teller;
teller = teller + 1;
return tall; // TODO
}
};
}
@Override
public int getLow() {
......@@ -39,12 +43,6 @@ public class Range implements Iterable<Integer>, IRange{
public int getHigh() {
return high;
}
@Override
public Iterator<Integer> iterator() {
return new RangeIterator();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment