Skip to content

Commit

Permalink
closes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
map555 committed Sep 24, 2021
1 parent 7412f5c commit 5a27ece
Show file tree
Hide file tree
Showing 19 changed files with 848 additions and 418 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class RandomInteger extends RandomPicker<Integer> implements RelativePick
*/
protected int m_max;

//TODO: talk to sylvain about the default interval problem in test
/**
* Default constructor
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;

public class AffineTransformTest
{
@ Test
public void sameValuesSameSeedInteger()
{
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int i = 0; i < 10; i++)
{
RandomInteger random_integer = new RandomInteger(0, 1000000);
random_integer.setSeed(int_list.get(i));
int random_seed = random_integer.pick();
int random_val = random_integer.pick();
RandomInteger random_integer1 = new RandomInteger(0, 1000);
Expand All @@ -32,27 +37,36 @@ public void sameValuesSameSeedInteger()
@ Test
public void integerInterval()
{
int min = 0;
int max = 25;
RandomInteger random_integer = new RandomInteger(min, max);
RandomInteger random_integer2 = new RandomInteger(0, 100000);
random_integer.setSeed(random_integer2.pick());
AffineTransform.AffineTransformInteger affine_transform_integer = new AffineTransform
.AffineTransformInteger(random_integer, 2, 0);
for (int i = 0; i < 100; i++)
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int j=0; j<10;j++)
{
int random_val = affine_transform_integer.pick();
Assertions.assertTrue(min <= random_val && random_val <= (2 * max));
int min = 0;
int max = 25;
RandomInteger random_integer = new RandomInteger(min, max);
random_integer.setSeed(int_list.get(j));
AffineTransform.AffineTransformInteger affine_transform_integer = new AffineTransform
.AffineTransformInteger(random_integer, 2, 0);
for (int i = 0; i < 100; i++)
{
int random_val = affine_transform_integer.pick();
Assertions.assertTrue(min <= random_val && random_val <= (2 * max));
}
}

}

@ Test
public void sameValuesSameSeedFloat()
{
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int i = 0; i < 10; i++)
{
int random_seed = int_list.get(i);
RandomInteger random_integer = new RandomInteger(0, 1000000);
int random_seed = random_integer.pick();
random_integer.setSeed(random_seed);

int random_val = random_integer.pick();
RandomFloat random_float = new RandomFloat();
RandomFloat random_float1 = new RandomFloat();
Expand All @@ -76,18 +90,24 @@ public void sameValuesSameSeedFloat()
@ Test
public void floatInterval()
{
int min = 0;
int max = 25;
RandomFloat random_float = new RandomFloat(min, max);
RandomInteger random_integer = new RandomInteger(0, 100000);
random_float.setSeed(random_integer.pick());
AffineTransform.AffineTransformFloat affine_transform_float = new AffineTransform
.AffineTransformFloat(random_float, 2, 0);
for (int i = 0; i < 100; i++)
{
float random_val = affine_transform_float.pick();
Assertions.assertTrue(min <= random_val && random_val <= (2 * max));
}
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for(int j=0; j<10; j++)
{
int min = 0;
int max = 25;
int random_seed = int_list.get(j);
RandomFloat random_float = new RandomFloat(min, max);
random_float.setSeed(random_seed);
AffineTransform.AffineTransformFloat affine_transform_float = new AffineTransform
.AffineTransformFloat(random_float, 2, 0);
for (int i = 0; i < 100; i++)
{
float random_val = affine_transform_float.pick();
Assertions.assertTrue(min <= random_val && random_val <= (2 * max));
}
}

}

@Test
Expand Down Expand Up @@ -119,11 +139,16 @@ public void outputTest()
@Test
public void duplicateWithStateFloat()
{
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int i = 0; i < 10; i++)
{
int random_seed = int_list.get(i);
RandomInteger random_integer = new RandomInteger(0, 1000000);
random_integer.setSeed(random_seed);
int random_val = random_integer.pick();
RandomFloat random_float = new RandomFloat();
random_float.setSeed(random_seed);
AffineTransform.AffineTransformFloat affine_transform_float = new AffineTransform
.AffineTransformFloat(random_float, random_val, 0);
AffineTransform.AffineTransformFloat affine_transform_float_copy = affine_transform_float
Expand All @@ -139,11 +164,16 @@ public void duplicateWithStateFloat()
@Test
public void duplicateWithoutStateFloat()
{
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int i = 0; i < 10; i++)
{
int random_seed = int_list.get(i);
RandomInteger random_integer = new RandomInteger(0, 1000000);
random_integer.setSeed(random_seed);
int random_val = random_integer.pick();
RandomFloat random_float = new RandomFloat();
random_float.setSeed(random_seed);
AffineTransform.AffineTransformFloat affine_transform_float = new AffineTransform
.AffineTransformFloat(random_float, random_val, 0);
for (int j = 0; j < 100; j++)
Expand All @@ -164,11 +194,16 @@ public void duplicateWithoutStateFloat()
@Test
public void duplicateWithStateInteger()
{
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int i = 0; i < 10; i++)
{
RandomInteger random_integer = new RandomInteger(0, 1000);
int random_seed = int_list.get(i);
RandomInteger random_integer = new RandomInteger(0, 1000000);
random_integer.setSeed(random_seed);
int random_val = random_integer.pick();
RandomInteger random_integer1 = new RandomInteger(0, 1000);
random_integer1.setSeed(random_seed);
AffineTransform.AffineTransformInteger affine_transform_integer = new AffineTransform
.AffineTransformInteger(random_integer1, random_val, 0);
for (int j = 0; j < 100; j++)
Expand All @@ -185,11 +220,15 @@ public void duplicateWithStateInteger()
@Test
public void duplicateWithoutStateInteger()
{
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int i = 0; i < 10; i++)
{
RandomInteger random_integer = new RandomInteger(0, 1000);
int random_val = random_integer.pick();
int random_seed = int_list.get(i);
RandomInteger random_integer = new RandomInteger(0, 1000000);
random_integer.setSeed(random_seed);
RandomInteger random_integer1 = new RandomInteger(0, 1000);
random_integer1.setSeed(random_seed);

AffineTransform.AffineTransformInteger affine_transform_integer = new AffineTransform
.AffineTransformInteger(random_integer1, 1, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
package ca.uqac.lif.synthia.random;

import ca.uqac.lif.synthia.exception.NoMoreElementException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.function.Executable;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.List;



public class BoundedPickerTest
{
@Test public void sameValuesSameSeed()
{
for (int i = 0; i < 10000; i++)
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int i = 0; i < 10; i++)
{
RandomInteger random_integer = new RandomInteger(0, 10000);

RandomInteger random_integer1 = new RandomInteger(1, 1000);
RandomInteger random_integer2 = new RandomInteger(1, 1000);
RandomFloat random_float = new RandomFloat();
RandomFloat random_float1 = new RandomFloat();
int randomSeed = random_integer.pick();
int randomSeed = int_list.get(i);
random_integer1.setSeed(randomSeed);
random_integer2.setSeed(randomSeed);
random_float.setSeed(randomSeed);
Expand All @@ -27,7 +31,7 @@ public class BoundedPickerTest
BoundedPicker bounded_picker1 = new BoundedPicker(random_float1, random_integer2.pick());
while (!bounded_picker.isDone())
{
Assertions.assertEquals(bounded_picker.pick(), bounded_picker1.pick());
Assert.assertEquals(bounded_picker.pick(), bounded_picker1.pick());
}
}
}
Expand All @@ -37,10 +41,15 @@ public void duplicateWithState()
{
int min = 50;
int max = 10000;
for (int i = 0; i < 1000; i++)
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int i = 0; i < 10; i++)
{
int random_seed = int_list.get(i);
RandomInteger random_integer = new RandomInteger(min, max);
RandomFloat random_float = new RandomFloat();
random_float.setSeed(random_seed);
random_integer.setSeed(random_seed);
BoundedPicker bounded_picker = new BoundedPicker(random_float, random_integer.pick());

for (int j = 0; j < (min - 1) ; j++)
Expand All @@ -52,7 +61,7 @@ public void duplicateWithState()

while (!bounded_picker.isDone())
{
Assertions.assertEquals(bounded_picker.pick(), bounded_picker_copy.pick());
Assert.assertEquals(bounded_picker.pick(), bounded_picker_copy.pick());
}

}
Expand All @@ -63,10 +72,15 @@ public void duplicateWithoutState()
{
int min = 50;
int max = 10000;
for (int i = 0; i < max; i++)
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for (int i = 0; i < 10; i++)
{
int random_seed = int_list.get(i);
RandomInteger random_integer = new RandomInteger(min, max);
RandomFloat random_float = new RandomFloat();
random_float.setSeed(random_seed);
random_integer.setSeed(random_seed);
BoundedPicker bounded_picker = new BoundedPicker(random_float, random_integer.pick());

for (int j = 0; j < (min - 1); j++)
Expand All @@ -78,7 +92,7 @@ public void duplicateWithoutState()

while (bounded_picker.isDone())
{
Assertions.assertNotEquals(bounded_picker.pick(), bounded_picker_copy.pick());
Assert.assertNotEquals(bounded_picker.pick(), bounded_picker_copy.pick());
}


Expand All @@ -87,42 +101,58 @@ public void duplicateWithoutState()

while (!bounded_picker.isDone())
{
Assertions.assertEquals(bounded_picker.pick(), bounded_picker_copy.pick());
Assert.assertEquals(bounded_picker.pick(), bounded_picker_copy.pick());
}
}
}

@Test
public void isDone()
{
BoundedPicker bounded_picker = new BoundedPicker(new RandomInteger(0, 100), 100);

for (int i = 0; i < 100; i++)
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();

for(int j=0; j<10; j++)
{
Assertions.assertEquals(false, bounded_picker.isDone());
bounded_picker.pick();
RandomInteger rand_int = new RandomInteger(0,100);
rand_int.setSeed(int_list.get(j));
BoundedPicker bounded_picker = new BoundedPicker(rand_int, 100);
for (int i = 0; i < 100; i++)
{
Assert.assertEquals(false, bounded_picker.isDone());
bounded_picker.pick();
}
Assert.assertEquals(true, bounded_picker.isDone());
}

Assertions.assertEquals(true, bounded_picker.isDone());



}

@Test
@Test(expected = NoMoreElementException.class)
public void noMoreElementException()
{
BoundedPicker bounded_picker = new BoundedPicker(new RandomInteger(0, 100), 100);

for (int i = 0; i < 100; i++)
{
Assertions.assertEquals(false, bounded_picker.isDone());
bounded_picker.pick();
}
assertThrows(NoMoreElementException.class, new Executable()
SeedsForRandomGenerationTests seeds = new SeedsForRandomGenerationTests();
List<Integer> int_list = seeds.getGeneralSeeds();
for(int j=0; j<10; j++)
{
@Override public void execute() throws Throwable

RandomInteger rand_int = new RandomInteger(0, 100);
rand_int.setSeed(int_list.get(j));

BoundedPicker bounded_picker = new BoundedPicker(rand_int, 100);

for (int i = 0; i < 100; i++)
{
Assert.assertEquals(false, bounded_picker.isDone());
bounded_picker.pick();
}
});

bounded_picker.pick();

}

}
}
Loading

0 comments on commit 5a27ece

Please sign in to comment.