~ubuntu-branches/ubuntu/trusty/eclipse-linuxtools/trusty

« back to all changes in this revision

Viewing changes to systemtap/org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.tests/src/org/eclipse/linuxtools/systemtap/ui/graphingapi/nonui/tests/structures/NumberTypeTest.java

  • Committer: Package Import Robot
  • Author(s): tony mancill
  • Date: 2013-05-13 21:43:22 UTC
  • mfrom: (1.2.1) (2.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20130513214322-6frgd9du1n0w2uo7
Tags: 1.2.1-1
* Team upload.
* New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
package org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.tests.structures;
13
13
 
 
14
import static org.junit.Assert.assertEquals;
 
15
import static org.junit.Assert.assertTrue;
 
16
 
14
17
import org.eclipse.linuxtools.systemtap.ui.graphingapi.nonui.structures.NumberType;
15
 
 
16
 
import junit.framework.TestCase;
17
 
 
18
 
public class NumberTypeTest extends TestCase {
19
 
        public NumberTypeTest(String name) {
20
 
                super(name);
21
 
        }
22
 
 
23
 
        protected void setUp() throws Exception {
24
 
                super.setUp();
25
 
        }
26
 
 
 
18
import org.junit.Test;
 
19
 
 
20
public class NumberTypeTest {
 
21
        @Test
27
22
        public void testGetNumber() {
28
 
                Number n = NumberType.getNumber(new Integer(3), 3.2);
 
23
                Number n = NumberType.getNumber(3, 3.2);
29
24
                assertTrue(n instanceof Integer);
30
25
                assertEquals(3, n.intValue());
31
26
 
32
 
                n = NumberType.getNumber(new Double(3), 3.2);
 
27
                n = NumberType.getNumber(3d, 3.2);
33
28
                assertTrue(n instanceof Double);
34
29
                assertEquals(3.2, n.doubleValue(), 0.0);
35
30
 
36
 
                n = NumberType.getNumber(new Float(3), 3.2);
 
31
                n = NumberType.getNumber(3f, 3.2);
37
32
                assertTrue(n instanceof Float);
38
33
                assertEquals(3.2, n.floatValue(), 0.0001);
39
34
 
40
 
                n = NumberType.getNumber(new Long(3), 3.2);
 
35
                n = NumberType.getNumber(3L, 3.2);
41
36
                assertTrue(n instanceof Long);
42
37
                assertEquals(3, n.longValue());
43
38
 
44
 
                n = NumberType.getNumber(new Byte((byte)3), 3.2);
 
39
                n = NumberType.getNumber((byte)3, 3.2);
45
40
                assertTrue(n instanceof Byte);
46
41
                assertEquals(3, n.byteValue());
47
42
 
48
 
                n = NumberType.getNumber(new Short((short)3), 3.2);
 
43
                n = NumberType.getNumber((short)3, 3.2);
49
44
                assertTrue(n instanceof Short);
50
45
                assertEquals(3, n.shortValue());
51
46
        }
52
 
        
 
47
        @Test
53
48
        public void testObj2num() {
54
 
                Object[] obj = new Object[] {new Integer(3), new Double(2.3), new Float(4.2)};
 
49
                Object[] obj = new Object[] {3, 2.3d, 4.2f};
55
50
                Number[] num = NumberType.obj2num(obj);
56
51
                
57
52
                assertEquals(0, NumberType.obj2num("a").intValue());
63
58
                assertEquals(2.3, num[1].doubleValue(), 0.00001);
64
59
                assertEquals(4.2, num[2].doubleValue(), 0.00001);
65
60
        }
66
 
        
 
61
        @Test
67
62
        public void testCleanObj2Num() {
68
63
                assertEquals(3, NumberType.cleanObj2Num("3").intValue());
69
64
                assertEquals(3.2, NumberType.cleanObj2Num("3.2").doubleValue(), 0.00001);
70
65
                assertEquals(3, NumberType.cleanObj2Num(new Integer(3)).intValue());
71
66
        }
72
67
        
73
 
        protected void tearDown() throws Exception {
74
 
                super.tearDown();
75
 
        }
76
68
}