KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > handlers > YDoubleTestCase


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.db4ounit.common.handlers;
22
23 import com.db4o.*;
24
25 import db4ounit.Assert;
26 import db4ounit.extensions.AbstractDb4oTestCase;
27
28 /**
29  * @exclude
30  */

31 public class YDoubleTestCase extends AbstractDb4oTestCase {
32     
33     private TypeHandler4 _handler;
34     
35     protected void db4oSetupBeforeStore() throws Exception JavaDoc {
36         _handler = new YDouble(stream());
37     }
38     
39     public void testMarshalling() {
40         final Double JavaDoc expected = new Double JavaDoc(1.1);
41         
42         YapReader buffer = new YapReader(_handler.linkLength());
43         _handler.writeIndexEntry(buffer, expected);
44         
45         buffer.seek(0);
46         final Object JavaDoc actual = _handler.readIndexEntry(buffer);
47         Assert.areEqual(expected, actual);
48     }
49
50     public void testComparison() {
51         assertComparison(0, 1.1, 1.1);
52         assertComparison(1, 1.0, 1.1);
53         assertComparison(-1, 1.1, 0.5);
54     }
55
56     private void assertComparison(final int expected, final double prepareWith, final double compareTo) {
57         _handler.prepareComparison(new Double JavaDoc(prepareWith));
58         final Double JavaDoc doubleCompareTo = new Double JavaDoc(compareTo);
59         Assert.areEqual(expected, _handler.compareTo(doubleCompareTo));
60         switch (expected) {
61         case 0:
62             Assert.isTrue(_handler.isEqual(doubleCompareTo));
63             Assert.isFalse(_handler.isGreater(doubleCompareTo));
64             Assert.isFalse(_handler.isSmaller(doubleCompareTo));
65             break;
66         case 1:
67             Assert.isFalse(_handler.isEqual(doubleCompareTo));
68             Assert.isTrue(_handler.isGreater(doubleCompareTo));
69             Assert.isFalse(_handler.isSmaller(doubleCompareTo));
70             break;
71         case -1:
72             Assert.isFalse(_handler.isEqual(doubleCompareTo));
73             Assert.isFalse(_handler.isGreater(doubleCompareTo));
74             Assert.isTrue(_handler.isSmaller(doubleCompareTo));
75             break;
76         }
77         
78     }
79 }
80
Popular Tags