CheckUtils { public static boolean areEquivalent(@Nullable Tree leftTree, @Nullable Tree rightTree) { if (leftTree == rightTree) { return true; } if (leftTree == null || rightTree == null) { return false; } if (leftTree.getKind() != rightTree.getKind() || leftTree.children().size() != rightTree.children().size()) { return false; } if (leftTree.children().isEmpty() && rightTree.children().isEmpty()) { return areLeavesEquivalent(leftTree, rightTree); } List<Tree> children1 = leftTree.children(); List<Tree> children2 = rightTree.children(); for (int i = 0; i < children1.size(); i++) { if (!areEquivalent(children1.get(i), children2.get(i))) { return false; } } return true; } private  CheckUtils(); static boolean areEquivalent(@Nullable Tree leftTree, @Nullable Tree rightTree); static ClassDef getParentClassDef(Tree tree); static boolean classHasInheritance(ClassDef classDef);  }
@Test public void statement_equivalence() { assertThat(CheckUtils.areEquivalent(parse("x = x + 1"), parse("x = x + 1"))).isTrue(); assertThat(CheckUtils.areEquivalent(parse("x = x + 1"), parse("x = x + 1"))).isTrue(); assertThat(CheckUtils.areEquivalent(parse("x = x + 1"), parse("x = x + 1"))).isTrue(); assertThat(CheckUtils.areEquivalent(parse("x = x + 1"), parse("x = x + 2"))).isFalse(); assertThat(CheckUtils.areEquivalent(parse("foo()"), parse("foo()"))).isTrue(); assertThat(CheckUtils.areEquivalent(parse("foo()"), parse("foo"))).isFalse(); assertThat(CheckUtils.areEquivalent(parse("foo"), parse("foo()"))).isFalse(); }
@Test public void comparison_equivalence() { assertThat(CheckUtils.areEquivalent(parse("foo is None"), parse("foo is not None"))).isFalse(); assertThat(CheckUtils.areEquivalent(parse("x < 2"), parse("x > 2"))).isFalse(); assertThat(CheckUtils.areEquivalent(parse("foo is None"), parse("foo is None"))).isTrue(); assertThat(CheckUtils.areEquivalent(parse("x < 1"), parse("x < 1"))).isTrue(); }
@Test public void tree_equivalence() { assertThat(CheckUtils.areEquivalent(new ArgListImpl(Collections.emptyList(), Collections.emptyList()), new ArgListImpl(Collections.emptyList(), Collections.emptyList()))).isTrue(); }
@Test public void null_equivalence() { assertThat(CheckUtils.areEquivalent(null, null)).isTrue(); assertThat(CheckUtils.areEquivalent(null, parse("class clazz(): \n pass"))).isFalse(); assertThat(CheckUtils.areEquivalent(parse("class clazz(): \n pass"), null)).isFalse(); }
@Test public void statement_list_equivalence() { assertThat(CheckUtils.areEquivalent(parse("foo()\nbar()"), parse("foo()\nbar()"))).isTrue(); assertThat(CheckUtils.areEquivalent(parse("foo()\n "), parse("foo()\n"))).isTrue(); assertThat(CheckUtils.areEquivalent(parse("foo()\n"), parse("foo()\n "))).isTrue(); assertThat(CheckUtils.areEquivalent(parse("foo()"), parse("foo()\nfoo()"))).isFalse(); assertThat(CheckUtils.areEquivalent(parse("foo()\nfoo()"), parse("foo()"))).isFalse(); assertThat(CheckUtils.areEquivalent(parse("foo()\nbar()"), parse("foo()\nbar"))).isFalse(); }
@Test public void lambda_equivalence() { assertThat(CheckUtils.areEquivalent(parse("x = lambda a : a + 10"), parse("x = lambda a : a + 10"))).isTrue(); assertThat(CheckUtils.areEquivalent(parse("x = lambda a : a + 10"), parse("x = lambda a : a + 5"))).isFalse(); }