30-1-3

public class VectorDataItemTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(VectorDataItemTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public VectorDataItemTests(String name) { super(name); } /** * Test that the equals() method distinguishes all fields. */ public void testEquals() { // default instances VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); VectorDataItem v2 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); assertTrue(v1.equals(v2)); assertTrue(v2.equals(v1)); v1 = new VectorDataItem(1.1, 2.0, 3.0, 4.0); assertFalse(v1.equals(v2)); v2 = new VectorDataItem(1.1, 2.0, 3.0, 4.0); assertTrue(v1.equals(v2)); v1 = new VectorDataItem(1.1, 2.2, 3.0, 4.0); assertFalse(v1.equals(v2)); v2 = new VectorDataItem(1.1, 2.2, 3.0, 4.0); assertTrue(v1.equals(v2)); v1 = new VectorDataItem(1.1, 2.2, 3.3, 4.0); assertFalse(v1.equals(v2)); v2 = new VectorDataItem(1.1, 2.2, 3.3, 4.0); assertTrue(v1.equals(v2)); v1 = new VectorDataItem(1.1, 2.2, 3.3, 4.4); assertFalse(v1.equals(v2)); v2 = new VectorDataItem(1.1, 2.2, 3.3, 4.4); assertTrue(v1.equals(v2)); } /** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); VectorDataItem v2 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); assertTrue(v1.equals(v2)); int h1 = v1.hashCode(); int h2 = v2.hashCode(); assertEquals(h1, h2); } /** * Check cloning. */ public void testCloning() { VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); VectorDataItem v2 = null; try { v2 = (VectorDataItem) v1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(v1 != v2); assertTrue(v1.getClass() == v2.getClass()); assertTrue(v1.equals(v2)); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); VectorDataItem v2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(v1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); v2 = (VectorDataItem) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(v1, v2);
public class YIntervalDataItemTests extends TestCase { /** * Returns the tests as a test suite. * * @return The test suite. */ public static Test suite() { return new TestSuite(YIntervalDataItemTests.class); } /** * Constructs a new set of tests. * * @param name the name of the tests. */ public YIntervalDataItemTests(String name) { super(name); } private static final double EPSILON = 0.00000000001; /** * Some checks for the constructor. */ public void testConstructor1() { YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 3.0, 4.0); assertEquals(new Double(1.0), item1.getX()); assertEquals(2.0, item1.getYValue(), EPSILON); assertEquals(3.0, item1.getYLowValue(), EPSILON); assertEquals(4.0, item1.getYHighValue(), EPSILON); } /** * Confirm that the equals method can distinguish all the required fields. */ public void testEquals() { YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5); YIntervalDataItem item2 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5); assertTrue(item1.equals(item2)); assertTrue(item2.equals(item1)); // x item1 = new YIntervalDataItem(1.1, 2.0, 1.5, 2.5); assertFalse(item1.equals(item2)); item2 = new YIntervalDataItem(1.1, 2.0, 1.5, 2.5); assertTrue(item1.equals(item2)); // y item1 = new YIntervalDataItem(1.1, 2.2, 1.5, 2.5); assertFalse(item1.equals(item2)); item2 = new YIntervalDataItem(1.1, 2.2, 1.5, 2.5); assertTrue(item1.equals(item2)); // yLow item1 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.5); assertFalse(item1.equals(item2)); item2 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.5); assertTrue(item1.equals(item2)); // yHigh item1 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.55); assertFalse(item1.equals(item2)); item2 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.55); assertTrue(item1.equals(item2)); } /** * Some checks for the clone() method. */ public void testCloning() { YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5); YIntervalDataItem item2 = null; try { item2 = (YIntervalDataItem) item1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(item1 != item2); assertTrue(item1.getClass() == item2.getClass()); assertTrue(item1.equals(item2)); } /** * Serialize an instance, restore it, and check for equality. */ public void testSerialization() { YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5); YIntervalDataItem item2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(item1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); item2 = (YIntervalDataItem) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(item1, item2);

Clone fragments detected by clone detection tool
File path: /jfreechart-1.0.10/tests/org/jfree/data/xy/junit/VectorDataItemTests.java |  | File path: /jfreechart-1.0.10/tests/org/jfree/data/xy/junit/YIntervalDataItemTests.java
Method name: `` |  | Method name: ``
Number of AST nodes: 0 |  | Number of AST nodes: 0

1

    public class VectorDataItemTests extends TestCase {↵

1

    public class YIntervalDataItemTests extends TestCase {↵

2

        ↵

2

        /**↵

3

        /**↵

3

         * Returns the tests as a test suite.↵

4

         * Returns the tests as a test suite.↵

4

         *↵

5

         *↵

5

         * @return The test suite.↵

6

         * @return The test suite.↵

6

         */↵

7

         */↵

7

        public static Test suite() {↵

8

        public static Test suite() {↵

8

            return new TestSuite(VectorDataItemTests.class);↵

9

            return new TestSuite(YIntervalDataItemTests.class);↵

9

        }↵

10

        }↵

10

        /**↵

11

        /**↵

11

         * Constructs a new set of tests.↵

12

         * Constructs a new set of tests.↵

12

         *↵

13

         *↵

13

         * @param name  the name of the tests.↵

14

         * @param name  the name of the tests.↵

14

         */↵

15

         */↵

15

        public VectorDataItemTests(String name) {↵

16

        public YIntervalDataItemTests(String name) {↵

16

            super(name);↵

17

            super(name);↵

17

        }↵

18

        }↵

18

        /**↵

19

        ↵

19

         * Test that the equals() method distinguishes all fields.↵

20

         */↵

21

        public void testEquals() {        ↵

22

            // default instances↵

23

            Vector↵

20

    private static final double EPSILON = 0.00000000001;↵

21

        ↵

22

        /**↵

23

         * Some checks for the constructor.↵

24

         */↵

25

        public void testConstructor1() {↵

24

    DataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0);↵

26

            YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 3.0, 4.0);↵

25

            VectorDataItem v2 = new VectorDataItem(1.0, 2.0, 3.0, 4.0↵

27

            assertEquals(new Double(1.0), item1.getX());↵

28

            assertEquals(2.0, item1.getYValue(), EPSILON);↵

26

    );↵

29

            assertEquals(3.0, item1.getYLowValue(), EPSILON);↵

27

            assertTrue(v1.equals(v2));↵

30

            assert↵

28

            assertTrue(v2.equals(v1));↵

29

            v1 = new Vector↵

31

    Equals(4.0, item1.getYHighValue(), EPSILON);↵

32

        }↵

33

        ↵

34

        /**↵

35

         * Confirm that the equals method can distinguish all the required fields.↵

36

         */↵

37

        public void testEquals() {↵

30

    DataItem(1.1, 2.0, 3.0, 4.0);↵

38

            YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5);↵

31

            assertFalse(v1.equals(v2));↵

39

            ↵

32

            v2 = new VectorDataItem(1.1, 2.0, 3.0, 4.0);↵

40

    YIntervalDataItem item2 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5);↵

33

            assertTrue(v1.equals(v2));↵

41

            assertTrue(item1.equals(item2));↵

34

            ↵

42

            ↵

35

            v1 = new Vector↵

43

    assertTrue(item2.equals(item1));↵

44

            // x↵

36

    DataItem(1.1, 2.2, 3.0, 4.0);↵

45

            item1 = new YIntervalDataItem(1.1, 2.0, 1.5, 2.5);↵

37

            assertFalse(v1.equals(v2));↵

46

            assertFalse(item1.equals(item2));↵

38

            v2 = new VectorDataItem(1.1, 2.2, 3.0, 4.0);↵

47

            item2 = new YIntervalDataItem(1.1, 2.0, 1.5, 2.5);↵

39

            assertTrue(v1.equals(v2));↵

48

            assertTrue(item1.equals(item2));↵

49

            ↵

40

            v1 = new Vector↵

50

            // y↵

41

    DataItem(1.1, 2.2, 3.3, 4.0);↵

51

            item1 = new YIntervalDataItem(1.1, 2.2, 1.5, 2.5);↵

42

            assertFalse(v1.equals(v2));↵

52

            assertFalse(item1.equals(item2));↵

43

            v2 = new VectorDataItem(1.1, 2.2, 3.3, 4.0);↵

53

            item2 = new YIntervalDataItem(1.1, 2.2, 1.5, 2.5);↵

44

            assertTrue(v1.equals(v2));↵

54

            assertTrue(item1.equals(item2));↵

45

        ↵

55

            // yLow↵

46

            v1 = new VectorDataItem(1.1, 2.2, 3.3, 4.4);↵

56

            item1 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.5);↵

47

            assertFalse(v1.equals(v2));↵

57

            assertFalse(item1.equals(item2));↵

48

            v2 = new VectorDataItem(1.1, 2.2, 3.3, 4.4);↵

58

            item2 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.5);↵

49

            assertTrue(v1.equals(v2));↵

59

            assertTrue(item1.equals(item2));↵

50

        }↵

51

        /**↵

52

         * Two objects that are equal are required to return the same hashCode. ↵

53

         */↵

54

        public void testHashcode() {↵

55

            VectorDataI↵

60

            // yHigh↵

56

    tem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0);↵

61

            item1 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.55);↵

57

            VectorDataItem v2 = new Vector↵

62

            assertFalse(item1.equals(item2));↵

58

    DataItem(1.0, 2.0, 3.0, 4.0);↵

63

            item2 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.55);↵

59

            assertTrue(v1.equals(v2));↵

64

            assertTrue(item1.equals(↵

60

            int h1 = v1.hashCode();↵

61

            int h2 = v2.hashCode();↵

62

            assertEquals(h1, h2);↵

65

    item2));↵

63

        }↵

66

        }↵

64

        ↵

65

        /**↵

67

        /**↵

66

         * Check cloning.↵

68

         * Some checks for the clone() method.↵

67

         */↵

69

         */↵

68

        public void testCloning() {↵

70

        public void testCloning() {↵

69

            VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0);↵

71

            YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5);↵

70

            VectorDataItem v2 = null;↵

72

            YIntervalDataItem item2 = null;↵

71

            try {↵

73

            try {↵

72

                v2 = (VectorDataItem) v1.clone();↵

74

                item2 = (YIntervalDataItem) item1.clone();↵

73

            }↵

75

            }↵

74

            catch (CloneNotSupportedException e) {↵

76

            catch (CloneNotSupportedException e) {↵

75

                e.printStackTrace();↵

77

                e.printStackTrace();↵

76

            }↵

78

            }↵

77

            assertTrue(v1 != v2);↵

79

            assertTrue(item1 != item2);↵

78

            assertTrue(v1.getClass() == v2.getClass());↵

80

            assertTrue(item1.getClass() == item2.getClass());↵

79

            assertTrue(v1.equals(v2));↵

81

            assertTrue(item1.equals(item2));↵

80

        }↵

82

        }↵

81

        /**↵

83

        /**↵

82

         * Serialize an instance, restore it, and check for equality.↵

84

         * Serialize an instance, restore it, and check for equality.↵

83

         */↵

85

         */↵

84

        public void testSerialization() {↵

86

        public void testSerialization() {↵

85

            VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0);↵

87

            YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5);↵

86

            VectorDataItem v2 = null;↵

88

            YIntervalDataItem item2 = null;↵

87

            try {↵

89

            try {↵

88

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

90

                ByteArrayOutputStream buffer = new ByteArrayOutputStream();↵

89

                ObjectOutput out = new ObjectOutputStream(buffer);↵

91

                ObjectOutput out = new ObjectOutputStream(buffer);↵

90

                out.writeObject(v1);↵

92

                out.writeObject(item1);↵

91

                out.close();↵

93

                out.close();↵

92

                ObjectInput in = new ObjectInputStream(↵

94

                ObjectInput in = new ObjectInputStream(↵

93

                        new ByteArrayInputStream(buffer.toByteArray()));↵

95

                        new ByteArrayInputStream(buffer.toByteArray()));↵

94

                v2 = (VectorDataItem) in.readObject();↵

96

                item2 = (YIntervalDataItem) in.readObject();↵

95

                in.close();↵

97

                in.close();↵

96

            }↵

98

            }↵

97

            catch (Exception e) {↵

99

            catch (Exception e) {↵

98

                e.printStackTrace();↵

100

                e.printStackTrace();↵

99

            }↵

101

            }↵

100

            assertEquals(v1, v2);↵

102

            assertEquals(item1, item2);↵

101

103

See real code fragment |  | See real code fragment

Summary
Number of common nesting structure subtrees | 0
Number of refactorable cases | 0
Number of non-refactorable cases | 0
Time elapsed for finding largest common nesting structure subtrees (ms) | 0.0
Clones location |
Number of node comparisons | 0