@Test(expected = AssertionError.class)
 public void testAssertThat_node_has_no_children_fails_when_node_has_children() {
   final Node root = new DefaultNode(String.class);
   final Node child = new DefaultNode(root, mock(Accessor.class), String.class);
   root.addChild(child);
   assertThat(root).node().hasNoChildren();
 }
Пример #2
0
 private StructuredGraph parseAndProcess(String snippet) {
   StructuredGraph graph = parse(snippet);
   LocalNode local = graph.getNodes(LocalNode.class).first();
   ConstantNode constant = ConstantNode.forInt(0, graph);
   for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
     n.replaceFirstInput(local, constant);
   }
   Map<Invoke, Double> hints = new HashMap<>();
   for (Invoke invoke : graph.getInvokes()) {
     hints.put(invoke, 1000d);
   }
   Assumptions assumptions = new Assumptions(false);
   new InliningPhase(
           runtime(),
           hints,
           replacements,
           assumptions,
           null,
           getDefaultPhasePlan(),
           OptimisticOptimizations.ALL)
       .apply(graph);
   new CanonicalizerPhase.Instance(runtime(), assumptions, true).apply(graph);
   new DeadCodeEliminationPhase().apply(graph);
   return graph;
 }
    @Before
    public void setUp() throws Exception {
      loadBalancer = new LoadBalancer();
      loadBalancer.setAccountId(1000);
      loadBalancer.setName("integration testing");
      loadBalancer.setPort(80);
      loadBalancer.setProtocol(LoadBalancerProtocol.POP3);

      Set<Node> nodes = new HashSet<Node>();
      Node node = new Node();
      node.setIpAddress("2.2.2.2");
      node.setPort(80);
      node.setCondition(NodeCondition.ENABLED);
      nodes.add(node);
      loadBalancer.setNodes(nodes);

      UserPages userPages = new UserPages();
      userPages.setErrorpage("aError");
      userPages.setLoadbalancer(loadBalancer);
      loadBalancer.setUserPages(userPages);

      loadBalancer = createLoadBalancerInActiveStatus(loadBalancer);

      accessList = new AccessList();
      accessList.setIpAddress("new ip");
      accessList.setType(AccessListType.ALLOW);
    }
 @Test
 public void testAssertThat_node_has_children_succeeds_when_children_are_present()
     throws Exception {
   final Node root = new DefaultNode(String.class);
   final Node child = new DefaultNode(root, mock(Accessor.class), String.class);
   root.addChild(child);
   assertThat(root).node().hasChildren();
 }
  @Test
  public void testCompareWithRemovedItem() throws Exception {
    final Collection<String> working = new LinkedList<String>();
    final Collection<String> base = new LinkedList<String>(Arrays.asList("foo"));

    final CollectionNode node = differ.compare(working, base);

    assertThat(node.hasChanges(), is(true));

    final Node child =
        node.getChild(PropertyPath.createBuilder().withRoot().withCollectionItem("foo").build());
    assertThat(child.getState(), is(Node.State.REMOVED));
  }
  @Test
  public void shouldHaveNoCycles() {
    Graph<String> graph = new Graph<>();
    packageDependencies.forEach(
        (key, set) -> {
          Node<String> node = graph.findOrCreateNode(key);
          set.stream()
              .filter(packageDependencies::containsKey)
              .forEach(target -> node.linkedTo(graph.findOrCreateNode(target)));
        });

    graph.topologicalSort();

    System.out.println("----------------------- dependencies:");
    System.out.println(graph.toString());
    System.out.println("-----------------------");
  }
  @Test
  public void testCompareWithChangedItem() throws Exception {
    final List<ObjectWithHashCodeAndEquals> working =
        Arrays.asList(new ObjectWithHashCodeAndEquals("foo", "1"));
    final List<ObjectWithHashCodeAndEquals> base =
        Arrays.asList(new ObjectWithHashCodeAndEquals("foo", "2"));

    final CollectionNode node = differ.compare(working, base);

    assertThat(node.hasChanges(), is(true));

    final PropertyPath propertyPath =
        PropertyPath.createBuilder()
            .withRoot()
            .withCollectionItem(new ObjectWithHashCodeAndEquals("foo"))
            .build();
    final Node child = node.getChild(propertyPath);
    assertThat(child.getState(), is(Node.State.CHANGED));
  }
Пример #8
0
  @Test
  public void testAst() {
    Node factorial =
        block(
            assign(id("factorial"), number(1)),
            assign(id("i"), number(5)),
            assign(id("test"), chars("cookies")),
            loop(
                id("i"),
                block(
                    assign(id("factorial"), times(id("factorial"), id("i"))),
                    assign(id("i"), minus(id("i"), number(1))))));
    StatementInterpreter runner = new StatementInterpreter();
    factorial.accept(runner);

    runner.symbols.printTable();

    /* Need to check first child... */
    for (SymbolTable s : runner.symbols.children) {
      assertEquals(0, s.get("i"));
      assertEquals(120, s.get("factorial"));
      assertEquals("cookies", s.get("test"));
    }
  }
Пример #9
0
  @Before
  public void setup() {
    nw = new Network();
    nw.setName("test network");

    dp = new DensityMap();

    nw.setNodes(new ArrayList<edu.berkeley.path.model_elements_base.Node>());
    nw.setLinks(new ArrayList<edu.berkeley.path.model_elements_base.Link>());

    Node nd1;
    Node nd2;
    Link ln;

    nd1 = new Node();
    nd1.setId(1L);
    nd1.setName("one");
    nd1.setType("Highway");
    nw.getNodes().add(nd1);

    nd2 = new Node();
    nd2.setId(2L);
    nd2.setName("two");
    nd2.setType("Highway");
    nw.getNodes().add(nd2);

    ln = new Link();
    ln.setId(3L);
    ln.setName("three");
    ln.setType("Highway");
    ln.setLaneCount(4.0);
    ln.setLength(1000.0);

    ln.setBegin(nd1);
    ln.setEnd(nd2);

    nw.getLinks().add(ln);
  }
 @Test(expected = AssertionError.class)
 public void testAssertThat_node_has_changed_state_fails_when_node_has_different_state() {
   final Node node = new DefaultNode(String.class);
   node.setState(Node.State.UNTOUCHED);
   assertThat(node).node().hasState(Node.State.CHANGED);
 }
 @Test
 public void testAssertThat_node_has_changed_state_succeeds_when_node_has_changed() {
   final Node node = new DefaultNode(String.class);
   node.setState(Node.State.CHANGED);
   assertThat(node).node().hasState(Node.State.CHANGED);
 }