aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/lib/collect
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-06-16 00:49:06 +0000
committerGravatar Yue Gan <yueg@google.com>2016-06-16 09:04:07 +0000
commit0e17046797f6cfed21755f2eed7c52c0a340d40c (patch)
tree1d965e43c4d0bcf9c6f1e45c95f742ec939bd6ac /src/test/java/com/google/devtools/build/lib/collect
parent8f5d9d55ce2974c13f57f7b08ab39f2a9dc64028 (diff)
Description redacted.
-- MOS_MIGRATED_REVID=125013752
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/collect')
-rw-r--r--src/test/java/com/google/devtools/build/lib/collect/nestedset/ExpanderTestBase.java23
-rw-r--r--src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetImplTest.java31
-rw-r--r--src/test/java/com/google/devtools/build/lib/collect/nestedset/RecordingUniqueifierTest.java132
3 files changed, 12 insertions, 174 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/collect/nestedset/ExpanderTestBase.java b/src/test/java/com/google/devtools/build/lib/collect/nestedset/ExpanderTestBase.java
index aff8e2cb7b..8877f71d5b 100644
--- a/src/test/java/com/google/devtools/build/lib/collect/nestedset/ExpanderTestBase.java
+++ b/src/test/java/com/google/devtools/build/lib/collect/nestedset/ExpanderTestBase.java
@@ -23,7 +23,6 @@ import com.google.common.collect.Lists;
import org.junit.Test;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -45,7 +44,7 @@ public abstract class ExpanderTestBase {
public void simple() {
NestedSet<String> s = prepareBuilder("c", "a", "b").build();
- assertTrue(Arrays.equals(simpleResult().toArray(), s.directMembers()));
+ assertEquals(simpleResult(), s.toList());
assertSetContents(simpleResult(), s);
}
@@ -53,7 +52,7 @@ public abstract class ExpanderTestBase {
public void simpleNoDuplicates() {
NestedSet<String> s = prepareBuilder("c", "a", "a", "a", "b").build();
- assertTrue(Arrays.equals(simpleResult().toArray(), s.directMembers()));
+ assertEquals(simpleResult(), s.toList());
assertSetContents(simpleResult(), s);
}
@@ -94,7 +93,6 @@ public abstract class ExpanderTestBase {
NestedSet<String> s1 = prepareBuilder().add("a").add("c").add("b").build();
NestedSet<String> s2 = prepareBuilder().addAll(ImmutableList.of("a", "c", "b")).build();
- assertTrue(Arrays.equals(s1.directMembers(), s2.directMembers()));
assertCollectionsEqual(s1.toCollection(), s2.toCollection());
assertCollectionsEqual(s1.toList(), s2.toList());
assertCollectionsEqual(Lists.newArrayList(s1), Lists.newArrayList(s2));
@@ -106,7 +104,6 @@ public abstract class ExpanderTestBase {
NestedSet<String> s2 = prepareBuilder().add("a").addAll(ImmutableList.of("b", "c")).add("d")
.build();
- assertTrue(Arrays.equals(s1.directMembers(), s2.directMembers()));
assertCollectionsEqual(s1.toCollection(), s2.toCollection());
assertCollectionsEqual(s1.toList(), s2.toList());
assertCollectionsEqual(Lists.newArrayList(s1), Lists.newArrayList(s2));
@@ -140,7 +137,6 @@ public abstract class ExpanderTestBase {
NestedSet<String> b = prepareBuilder("b").addTransitive(c).build();
NestedSet<String> a = prepareBuilder("a").addTransitive(b).build();
- assertTrue(Arrays.equals(new String[]{"a"}, a.directMembers()));
assertSetContents(chainResult(), a);
}
@@ -151,7 +147,6 @@ public abstract class ExpanderTestBase {
NestedSet<String> b = prepareBuilder("b").addTransitive(d).build();
NestedSet<String> a = prepareBuilder("a").addTransitive(b).addTransitive(c).build();
- assertTrue(Arrays.equals(new String[]{"a"}, a.directMembers()));
assertSetContents(diamondResult(), a);
}
@@ -208,20 +203,6 @@ public abstract class ExpanderTestBase {
assertEquals(expanderOrder(), s.getOrder());
}
- /**
- * In case we have inner NestedSets with different order (allowed by the builder). We should
- * maintain the order of the top-level NestedSet.
- */
- @Test
- public void regressionOnOneTransitiveDep() {
- NestedSet<String> subsub = NestedSetBuilder.<String>stableOrder().add("c").add("a").add("e")
- .build();
- NestedSet<String> sub = NestedSetBuilder.<String>stableOrder().add("b").add("d")
- .addTransitive(subsub).build();
- NestedSet<String> top = prepareBuilder().addTransitive(sub).build();
- assertSetContents(nestedResult(), top);
- }
-
@Test
public void nestingValidation() {
for (Order ordering : Order.values()) {
diff --git a/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetImplTest.java b/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetImplTest.java
index 5ffc7f1609..b72f89ca4b 100644
--- a/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetImplTest.java
+++ b/src/test/java/com/google/devtools/build/lib/collect/nestedset/NestedSetImplTest.java
@@ -13,7 +13,6 @@
// limitations under the License.
package com.google.devtools.build.lib.collect.nestedset;
-import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -27,8 +26,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-import java.util.Arrays;
-
/**
* Tests for {@link com.google.devtools.build.lib.collect.nestedset.NestedSet}.
*/
@@ -45,8 +42,7 @@ public class NestedSetImplTest {
public void simple() {
NestedSet<String> set = nestedSetBuilder("a").build();
- assertTrue(Arrays.equals(new String[]{"a"}, set.directMembers()));
- assertThat(set.transitiveSets()).isEmpty();
+ assertEquals(ImmutableList.of("a"), set.toList());
assertFalse(set.isEmpty());
}
@@ -59,15 +55,15 @@ public class NestedSetImplTest {
@Test
public void nestedToString() {
- NestedSet<String> b = nestedSetBuilder("b").build();
- NestedSet<String> c = nestedSetBuilder("c").build();
+ NestedSet<String> b = nestedSetBuilder("b1", "b2").build();
+ NestedSet<String> c = nestedSetBuilder("c1", "c2").build();
- assertEquals("{a, {b}}",
+ assertEquals("{{b1, b2}, a}",
nestedSetBuilder("a").addTransitive(b).build().toString());
- assertEquals("{a, {b}, {c}}",
+ assertEquals("{{b1, b2}, {c1, c2}, a}",
nestedSetBuilder("a").addTransitive(b).addTransitive(c).build().toString());
- assertEquals("{b}", nestedSetBuilder().addTransitive(b).build().toString());
+ assertEquals("{b1, b2}", nestedSetBuilder().addTransitive(b).build().toString());
}
@Test
@@ -148,13 +144,6 @@ public class NestedSetImplTest {
return new SetWrapper<E>(builder.build());
}
- // Same as flat(), but allows duplicate elements.
- @SafeVarargs
- private static <E> SetWrapper<E> flatWithDuplicates(E... directMembers) {
- return new SetWrapper<E>(
- NestedSetBuilder.wrap(Order.STABLE_ORDER, ImmutableList.copyOf(directMembers)));
- }
-
@SafeVarargs
private static <E> SetWrapper<E> nest(SetWrapper<E>... nested) {
NestedSetBuilder<E> builder = NestedSetBuilder.stableOrder();
@@ -191,16 +180,16 @@ public class NestedSetImplTest {
.addEqualityGroup(flat(3),
flat(3),
flat(3, 3)) // Element de-duplication.
- .addEqualityGroup(flatWithDuplicates(3, 3))
.addEqualityGroup(flat(4),
nest(flat(4))) // Automatic elision of one-element nested sets.
.addEqualityGroup(NestedSetBuilder.<Integer>linkOrder().add(4).build())
.addEqualityGroup(nestedSetBuilder("4").build()) // Like flat("4").
.addEqualityGroup(flat(3, 4),
flat(3, 4))
- // Shallow equality means that {{3},{5}} != {{3},{5}}.
- .addEqualityGroup(nest(flat(3), flat(5)))
- .addEqualityGroup(nest(flat(3), flat(5)))
+ // Make a couple sets deep enough that shallowEquals() fails.
+ // If this test case fails because you improve the representation, just delete it.
+ .addEqualityGroup(nest(nest(flat(3, 4), flat(5)), nest(flat(6, 7), flat(8))))
+ .addEqualityGroup(nest(nest(flat(3, 4), flat(5)), nest(flat(6, 7), flat(8))))
.addEqualityGroup(nest(myRef),
nest(myRef),
nest(myRef, myRef)) // Set de-duplication.
diff --git a/src/test/java/com/google/devtools/build/lib/collect/nestedset/RecordingUniqueifierTest.java b/src/test/java/com/google/devtools/build/lib/collect/nestedset/RecordingUniqueifierTest.java
deleted file mode 100644
index 13b363b4ed..0000000000
--- a/src/test/java/com/google/devtools/build/lib/collect/nestedset/RecordingUniqueifierTest.java
+++ /dev/null
@@ -1,132 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed 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 com.google.devtools.build.lib.collect.nestedset;
-
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.util.Preconditions;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Random;
-
-/**
- * Tests for {@link RecordingUniqueifier}.
- */
-@RunWith(JUnit4.class)
-public class RecordingUniqueifierTest {
-
- private static final Random RANDOM = new Random();
-
- private static final int VERY_SMALL = 3; // one byte
- private static final int SMALL = 11; // two bytes
- private static final int MEDIUM = 18; // three bytes -- unmemoed
- // For this one, the "* 8" is a bytes to bits (1 memo is 1 bit)
- private static final int LARGE = (RecordingUniqueifier.LENGTH_THRESHOLD * 8) + 3;
-
- private static final int[] SIZES = new int[] {VERY_SMALL, SMALL, MEDIUM, LARGE};
-
- private void doTest(int uniqueInputs, int deterministicHeadSize) throws Exception {
- Preconditions.checkArgument(deterministicHeadSize <= uniqueInputs,
- "deterministicHeadSize must be smaller than uniqueInputs");
-
- // Setup
-
- List<Integer> inputList = new ArrayList<>(uniqueInputs);
- Collection<Integer> inputsDeduped = new LinkedHashSet<>(uniqueInputs);
-
- for (int i = 0; i < deterministicHeadSize; i++) { // deterministic head
- inputList.add(i);
- inputsDeduped.add(i);
- }
-
- while (inputsDeduped.size() < uniqueInputs) { // random selectees
- Integer i = RANDOM.nextInt(uniqueInputs);
- inputList.add(i);
- inputsDeduped.add(i);
- }
-
- // Unmemoed run
-
- List<Integer> firstList = new ArrayList<>(uniqueInputs);
- RecordingUniqueifier recordingUniqueifier = new RecordingUniqueifier();
- for (Integer i : inputList) {
- if (recordingUniqueifier.isUnique(i)) {
- firstList.add(i);
- }
- }
-
- // Potentially memo'ed run
-
- List<Integer> secondList = new ArrayList<>(uniqueInputs);
- Object memo = recordingUniqueifier.getMemo();
- Uniqueifier uniqueifier = RecordingUniqueifier.createReplayUniqueifier(memo);
- for (Integer i : inputList) {
- if (uniqueifier.isUnique(i)) {
- secondList.add(i);
- }
- }
-
- // Evaluate results
-
- inputsDeduped = ImmutableList.copyOf(inputsDeduped);
- assertEquals("Unmemo'ed run has unexpected contents", inputsDeduped, firstList);
- assertEquals("Memo'ed run has unexpected contents", inputsDeduped, secondList);
- }
-
- private void doTestWithLucidException(int uniqueInputs, int deterministicHeadSize)
- throws Exception {
- try {
- doTest(uniqueInputs, deterministicHeadSize);
- } catch (Exception e) {
- throw new Exception("Failure in size: " + uniqueInputs, e);
- }
- }
-
- @Test
- public void noInputs() throws Exception {
- doTestWithLucidException(0, 0);
- }
-
- @Test
- public void allUnique() throws Exception {
- for (int size : SIZES) {
- doTestWithLucidException(size, size);
- }
- }
-
- @Test
- public void fuzzedWithDeterministic2() throws Exception {
- // The way that it is used, we know that the first two additions are not equal.
- // Optimizations were made for this case in small memos.
- for (int size : SIZES) {
- doTestWithLucidException(size, 2);
- }
- }
-
- @Test
- public void fuzzedWithDeterministic2_otherSizes() throws Exception {
- for (int i = 0; i < 100; i++) {
- int size = RANDOM.nextInt(10000) + 2;
- doTestWithLucidException(size, 2);
- }
- }
-}