Skip to content

Commit

Permalink
tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
pholser committed Nov 21, 2020
1 parent c91e25f commit e150c73
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,4 @@ a copy of this software and associated documentation files (the
package com.pholser.junit.quickcheck.examples.tree;

public interface Tree extends Visited<TreeVisitor> {
String LOWERCASE_CHARS = "abcdefghijklmnopqrstuvwxyz";

String UPPERCASE_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

String NUMBERS = "0123456789";

String ALL_MY_CHARS = LOWERCASE_CHARS + UPPERCASE_CHARS + NUMBERS;

int LABEL_SIZE = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,25 @@ a copy of this software and associated documentation files (the
import com.pholser.junit.quickcheck.examples.tree.Node;
import com.pholser.junit.quickcheck.examples.tree.TreeVisitor;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map;

public class TreeDeepestLeafVisitor implements TreeVisitor {
@Override public SimpleImmutableEntry<String, Integer> visit(Empty empty) {
@Override public Map.Entry<String, Integer> visit(Empty empty) {
return new SimpleImmutableEntry<>("", 0);
}

@Override public SimpleImmutableEntry<String, Integer> visit(Leaf leaf) {
@Override public Map.Entry<String, Integer> visit(Leaf leaf) {
return new SimpleImmutableEntry<>(leaf.value(), 0);
}

@Override public SimpleImmutableEntry<String, Integer> visit(Node node) {
@Override public Map.Entry<String, Integer> visit(Node node) {
@SuppressWarnings("unchecked")
SimpleImmutableEntry<String, Integer> leftResult =
(SimpleImmutableEntry<String, Integer>) node.left().accept(this);
Map.Entry<String, Integer> leftResult =
(Map.Entry<String, Integer>) node.left().accept(this);

@SuppressWarnings("unchecked")
SimpleImmutableEntry<String, Integer> rightResult =
(SimpleImmutableEntry<String, Integer>) node.right().accept(this);
Map.Entry<String, Integer> rightResult =
(Map.Entry<String, Integer>) node.right().accept(this);

int leftDepth = leftResult.getValue();
int rightDepth = rightResult.getValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/*
The MIT License
Copyright (c) 2010-2020 Paul R. Holser, Jr.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.pholser.junit.quickcheck.examples.convention;

public class Convention {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
/*
The MIT License
Copyright (c) 2010-2020 Paul R. Holser, Jr.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.pholser.junit.quickcheck.examples.convention;

import com.pholser.junit.quickcheck.generator.GenerationStatus;
import com.pholser.junit.quickcheck.generator.Generator;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;

public class ConventionGen extends Generator<Convention> {


public ConventionGen() {
super(Convention.class);
}

@Override
public Convention generate(SourceOfRandomness random, GenerationStatus status) {
@Override public Convention generate(
SourceOfRandomness random,
GenerationStatus status) {

return new Convention();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
/*
The MIT License
Copyright (c) 2010-2020 Paul R. Holser, Jr.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.pholser.junit.quickcheck.examples.convention;

import static org.junit.Assert.assertNotNull;
Expand All @@ -15,8 +40,7 @@

@RunWith(JUnitQuickcheck.class)
public class ConventionGenTest {
@Property
public void random_convention_objects_are_generated(
@Property public void generatesRandomConventionObjects(
Convention first,
Convention second) {

Expand All @@ -26,22 +50,21 @@ public void random_convention_objects_are_generated(
}

@Test
public void generator_class_is_not_defined_in_services_file()
throws Exception {

public void generatorClassIsNotDefinedInServicesFile() throws Exception {
String servicesFileName =
"META-INF/services/com.pholser.junit.quickcheck.generator.Generator";
Enumeration<URL> serviceFiles =
Thread.currentThread().getContextClassLoader().getResources(servicesFileName);
if (serviceFiles == null || !serviceFiles.hasMoreElements()) {
Thread.currentThread().getContextClassLoader()
.getResources(servicesFileName);
if (serviceFiles == null || !serviceFiles.hasMoreElements())
return;
}

while (serviceFiles.hasMoreElements()) {
URL serviceFile = serviceFiles.nextElement();

try (BufferedReader reader =
new BufferedReader(new InputStreamReader(serviceFile.openStream()))) {
new BufferedReader(
new InputStreamReader(serviceFile.openStream()))) {

assertTrue(
reader.lines().noneMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public AES128Keys() {
}

@Override public Key generate(
SourceOfRandomness random, GenerationStatus status) {
SourceOfRandomness random,
GenerationStatus status) {

KeyGenerator keygen;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public class SymmetricKeyCryptoPropertiesTest {

assertEquals(
plaintext,
new String(crypto.decrypt(enciphered, key), StandardCharsets.UTF_8 ));
new String(
crypto.decrypt(enciphered, key),
StandardCharsets.UTF_8));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@RunWith(JUnitQuickcheck.class)
public class AGeneratorTest {
@Property public void listAreCorrectlyGenerated(A a) {
a.getListOfB().forEach(b -> assertThat(b, instanceOf(B.class)));
a.getListOfB().forEach(b ->
assertThat(b, instanceOf(B.class)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

@RunWith(JUnitQuickcheck.class)
public class EitherTest {
@Property
public void withRanges(
@Property public void withRanges(
Either<
@InRange(minInt = 0) Integer,
@InRange(minDouble = -7.0, maxDouble = -4.0) Double> e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ static List<BigInteger> of(BigInteger n) {
}

private PrimeFactors() {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public NodeGenerator() {
s.setValue(TreeKeys.DEPTH, depth - 1);
return new Node(
subtree.generate(r, s),
subtree.generate(r, s)
);
subtree.generate(r, s));
}

@Override public boolean canRegisterAsType(Class<?> type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ a copy of this software and associated documentation files (the
import com.pholser.junit.quickcheck.examples.tree.visitor.TreeDeepestLeafVisitor;
import com.pholser.junit.quickcheck.examples.tree.visitor.TreeDepthVisitor;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.Map;

import org.junit.runner.RunWith;

@RunWith(JUnitQuickcheck.class)
Expand All @@ -46,8 +47,8 @@ public class TreePropertyTest {
TreeDeepestLeafVisitor visitor = new TreeDeepestLeafVisitor();

@SuppressWarnings("unchecked")
SimpleImmutableEntry<String, Integer> result =
(SimpleImmutableEntry<String, Integer>) t.accept(visitor);
Map.Entry<String, Integer> result =
(Map.Entry<String, Integer>) t.accept(visitor);

assertThat(result.getValue(), lessThanOrEqualTo(10));
}
Expand Down

0 comments on commit e150c73

Please sign in to comment.