commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [2/2] commons-rng git commit: Unit tests.
Date Wed, 19 Oct 2016 15:12:01 GMT
Unit tests.


Project: http://git-wip-us.apache.org/repos/asf/commons-rng/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-rng/commit/31392320
Tree: http://git-wip-us.apache.org/repos/asf/commons-rng/tree/31392320
Diff: http://git-wip-us.apache.org/repos/asf/commons-rng/diff/31392320

Branch: refs/heads/master
Commit: 313923203cbd7a365dd03547f63cbd1cbe134efb
Parents: a2ece1b
Author: Gilles <erans@apache.org>
Authored: Wed Oct 19 16:57:42 2016 +0200
Committer: Gilles <erans@apache.org>
Committed: Wed Oct 19 16:57:42 2016 +0200

----------------------------------------------------------------------
 .../rng/ProvidersCommonParametricTest.java      |  5 ++
 .../commons/rng/internal/BaseProviderTest.java  | 57 ++++++++++++++++++++
 2 files changed, 62 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-rng/blob/31392320/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java b/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java
index b997e34..c759600 100644
--- a/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java
+++ b/src/test/java/org/apache/commons/rng/ProvidersCommonParametricTest.java
@@ -407,6 +407,11 @@ public class ProvidersCommonParametricTest {
         ((RestorableUniformRandomProvider) generator).restoreState(state);
     }
 
+    @Test(expected=IllegalArgumentException.class)
+    public void testRestoreForeignState() {
+        ((RestorableUniformRandomProvider) generator).restoreState(new RandomProviderState()
{});
+    }
+
 
     ///// Support methods below.
 

http://git-wip-us.apache.org/repos/asf/commons-rng/blob/31392320/src/test/java/org/apache/commons/rng/internal/BaseProviderTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/rng/internal/BaseProviderTest.java b/src/test/java/org/apache/commons/rng/internal/BaseProviderTest.java
new file mode 100644
index 0000000..a1e05c9
--- /dev/null
+++ b/src/test/java/org/apache/commons/rng/internal/BaseProviderTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.rng.internal;
+
+import org.junit.Test;
+
+import org.apache.commons.rng.RestorableUniformRandomProvider;
+import org.apache.commons.rng.RandomSource;
+
+/**
+ * Tests for {@link BaseProvider}.
+ *
+ * This class should only contain unit tests that cover code paths not
+ * exercised elsewhere.  Those code paths are most probably only taken
+ * in case of a wrong implementation (and would therefore fail other
+ * tests too).
+ */
+public class BaseProviderTest {
+    @Test(expected=UnsupportedOperationException.class)
+    public void testMissingGetStateInternal() {
+        final RestorableUniformRandomProvider rng = new DummyGenerator();
+        rng.saveState();
+    }
+
+    @Test(expected=UnsupportedOperationException.class)
+    public void testMissingSetStateInternal() {
+        final RestorableUniformRandomProvider rng = new DummyGenerator();
+        rng.restoreState(new RandomSource.State(new byte[1]));
+    }
+}
+
+/**
+ * Dummy class for checking the behaviour of an incomplete implementation.
+ */
+class DummyGenerator extends org.apache.commons.rng.internal.source32.IntProvider {
+    /** {@inheritDoc} */
+    @Override
+    public int next() {
+        return 4; // https://www.xkcd.com/221/
+    }
+
+    // Missing overrides of "setStateInternal" and "getStateInternal".
+}


Mime
View raw message