001: /*
002: * $Id: TestSubtractFunction.java,v 1.5 2004/09/09 19:47:27 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2003 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb.functions;
042:
043: import java.math.BigDecimal;
044: import java.util.HashMap;
045: import java.util.Map;
046:
047: import junit.framework.Test;
048: import junit.framework.TestSuite;
049:
050: import org.axiondb.ColumnIdentifier;
051: import org.axiondb.Function;
052: import org.axiondb.RowDecorator;
053: import org.axiondb.engine.rows.SimpleRow;
054:
055: /**
056: * @version $Revision: 1.5 $ $Date: 2004/09/09 19:47:27 $
057: * @author Rodney Waldhoff
058: */
059: public class TestSubtractFunction extends
060: AbstractArithmeticFunctionTest {
061:
062: //------------------------------------------------------------ Conventional
063:
064: public TestSubtractFunction(String testName) {
065: super (testName);
066: }
067:
068: public static Test suite() {
069: TestSuite suite = new TestSuite(TestSubtractFunction.class);
070: return suite;
071: }
072:
073: //--------------------------------------------------------------- Lifecycle
074:
075: //--------------------------------------------------------------- Framework
076:
077: protected ConcreteFunction makeFunction() {
078: return new SubtractFunction();
079: }
080:
081: //------------------------------------------------------------------- Tests
082:
083: public void testMakeNewInstance() {
084: SubtractFunction function = new SubtractFunction();
085: assertTrue(function.makeNewInstance() instanceof SubtractFunction);
086: assertTrue(function.makeNewInstance() != function
087: .makeNewInstance());
088: }
089:
090: public void testInts() throws Exception {
091: Function function = makeFunction();
092: ColumnIdentifier sel1 = new ColumnIdentifier("foo");
093: function.addArgument(sel1);
094: ColumnIdentifier sel2 = new ColumnIdentifier("bar");
095: function.addArgument(sel2);
096:
097: Map map = new HashMap();
098: map.put(sel1, new Integer(0));
099: map.put(sel2, new Integer(1));
100: RowDecorator dec = new RowDecorator(map);
101:
102: dec.setRow(new SimpleRow(new Object[] { new Integer(1),
103: new Integer(15) }));
104: assertEquals(new BigDecimal("-14"), function.evaluate(dec));
105: }
106:
107: public void testLargeInts() throws Exception {
108: Function function = makeFunction();
109: ColumnIdentifier sel1 = new ColumnIdentifier("foo");
110: function.addArgument(sel1);
111: ColumnIdentifier sel2 = new ColumnIdentifier("bar");
112: function.addArgument(sel2);
113:
114: Map map = new HashMap();
115: map.put(sel1, new Integer(0));
116: map.put(sel2, new Integer(1));
117: RowDecorator dec = new RowDecorator(map);
118:
119: dec.setRow(new SimpleRow(new Object[] {
120: new Integer(Integer.MIN_VALUE), new Integer(1) }));
121: assertEquals(new BigDecimal(((Integer.MIN_VALUE)) - 1L),
122: function.evaluate(dec));
123: }
124:
125: public void testIntAndFloat() throws Exception {
126: Function function = makeFunction();
127: ColumnIdentifier sel1 = new ColumnIdentifier("foo");
128: function.addArgument(sel1);
129: ColumnIdentifier sel2 = new ColumnIdentifier("bar");
130: function.addArgument(sel2);
131:
132: Map map = new HashMap();
133: map.put(sel1, new Integer(0));
134: map.put(sel2, new Integer(1));
135: RowDecorator dec = new RowDecorator(map);
136:
137: dec.setRow(new SimpleRow(new Object[] { new Integer(1),
138: new Float(1.5f) }));
139: assertEquals(new BigDecimal("-0.5"), function.evaluate(dec));
140: }
141: }
|