Skip to content

Commit

Permalink
Unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilles committed Aug 30, 2016
1 parent efb4cc0 commit dd0a4e5
Showing 1 changed file with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ public void testStateWrongSize() {
RandomSource.restoreState(generator, state);
}

@Test(expected=UnsupportedOperationException.class)
public void testSaveStateWrongClass() {
RandomSource.saveState(new ForeignDummyGenerator());
}

@Test(expected=UnsupportedOperationException.class)
public void testRestoreStateWrongClass() {
RandomSource.restoreState(new ForeignDummyGenerator(),
new RandomSource.State(new byte[0]));
}

///// Support methods below.

/**
Expand Down Expand Up @@ -723,3 +734,57 @@ protected void setStateInternal(byte[] s) {
// No state.
}
}

/**
* Dummy class for checking that "save" and "restore" fail when a
* class is passed that is not providing the necessary functionality
* (i.e. a class that is not implemented by this library).
*/
class ForeignDummyGenerator implements UniformRandomProvider {
@Override
public void nextBytes(byte[] bytes) {
return;
}

@Override
public void nextBytes(byte[] bytes,
int start,
int len) {
return;
}

@Override
public int nextInt() {
return 0;
}

@Override
public int nextInt(int n) {
return 0;
}

@Override
public long nextLong() {
return 0;
}

@Override
public long nextLong(long n) {
return 0;
}

@Override
public boolean nextBoolean() {
return false;
}

@Override
public float nextFloat() {
return 0;
}

@Override
public double nextDouble() {
return 0;
}
}

0 comments on commit dd0a4e5

Please sign in to comment.