PageRenderTime 15ms CodeModel.GetById 2ms app.highlight 10ms RepoModel.GetById 2ms app.codeStats 0ms

/testability-explorer/src/test/java/com/google/test/metric/method/op/stack/Duplicate2Test.java

http://testability-explorer.googlecode.com/
Java | 92 lines | 78 code | 14 blank | 0 comment | 1 complexity | 6d43456577b99703972f0cc219cc6b10 MD5 | raw file
 1package com.google.test.metric.method.op.stack;
 2
 3import static java.util.Arrays.asList;
 4
 5import java.util.Arrays;
 6import java.util.List;
 7
 8import junit.framework.TestCase;
 9
10import com.google.test.metric.JavaType;
11import com.google.test.metric.Variable;
12import com.google.test.metric.method.Constant;
13
14public class Duplicate2Test extends TestCase {
15
16  public void testDup2Single() throws Exception {
17    Duplicate2 dup2 = new Duplicate2(1, 0);
18    assertEquals(2, dup2.getOperatorCount());
19    Variable v1 = var(1);
20    Variable v2 = var(2);
21    List<Variable> out = dup2.apply(asList(v1, v2));
22    assertList(out, v1, v2, v1, v2);
23    assertEquals("duplicate2", dup2.toString());
24  }
25
26  public void testDup2Double() throws Exception {
27    Duplicate2 dup2 = new Duplicate2(1, 0);
28    assertEquals(2, dup2.getOperatorCount());
29    Variable v1 = var(1l);
30    List<Variable> out = dup2.apply(asList(v1, v1));
31    assertList(out, v1, v1, v1, v1);
32    assertEquals("duplicate2", dup2.toString());
33  }
34
35  public void testDup2Offset1Single() throws Exception {
36    Duplicate2 dup2 = new Duplicate2(1, 1);
37    assertEquals(3, dup2.getOperatorCount());
38    Variable v1 = var(1);
39    Variable v2 = var(2);
40    Variable v3 = var(3);
41    List<Variable> out = dup2.apply(asList(v3, v2, v1));
42    assertList(out, v2, v1, v3, v2, v1);
43    assertEquals("duplicate2_X1", dup2.toString());
44  }
45
46  public void testDup2Offset1Double() throws Exception {
47    Duplicate2 dup2 = new Duplicate2(1, 1);
48    assertEquals(3, dup2.getOperatorCount());
49    Variable v1 = var(1l);
50    Variable v2 = var(2);
51    List<Variable> out = dup2.apply(asList(v2, v1, v1));
52    assertList(out, v1, v1, v2, v1, v1);
53    assertEquals("duplicate2_X1", dup2.toString());
54  }
55
56  public void testDup2Offset2Single() throws Exception {
57    Duplicate2 dup2 = new Duplicate2(1, 2);
58    assertEquals(4, dup2.getOperatorCount());
59    Variable v1 = var(1);
60    Variable v2 = var(2);
61    Variable v3 = var(3);
62    Variable v4 = var(4);
63    List<Variable> out = dup2.apply(asList(v4, v3, v2, v1));
64    assertList(out, v2, v1, v4, v3, v2, v1);
65    assertEquals("duplicate2_X2", dup2.toString());
66  }
67
68  public void testDup2Offset3Double() throws Exception {
69    Duplicate2 dup2 = new Duplicate2(1, 2);
70    assertEquals(4, dup2.getOperatorCount());
71    Variable v1 = var(1l);
72    Variable v2 = var(2);
73    Variable v3 = var(3);
74    List<Variable> out = dup2.apply(asList(v3, v2, v1, v1));
75    assertList(out, v1, v1, v3, v2, v1, v1);
76    assertEquals("duplicate2_X2", dup2.toString());
77  }
78
79  private void assertList(List<Variable> actual, Variable... expected) {
80    assertEquals(expected.length, actual.size());
81    String error = "\nExpecting: " + Arrays.toString(expected)
82        + "\n  Actual:" + actual + "\n";
83    for (int i = 0; i < expected.length; i++) {
84      assertEquals(error, expected[i], actual.get(i));
85    }
86  }
87
88  private Variable var(Object value) {
89    return new Constant(value, JavaType.fromClass(value.getClass()));
90  }
91
92}