001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.math.util; 019 020 import java.math.BigDecimal; 021 022 import junit.framework.TestCase; 023 024 import org.apache.commons.math.MathException; 025 import org.apache.commons.math.TestUtils; 026 027 /** 028 * @version $Revision: 795975 $ $Date: 2009-07-20 15:50:12 -0400 (Mon, 20 Jul 2009) $ 029 */ 030 public class DefaultTransformerTest extends TestCase { 031 /** 032 * 033 */ 034 public void testTransformDouble() throws Exception { 035 double expected = 1.0; 036 Double input = Double.valueOf(expected); 037 DefaultTransformer t = new DefaultTransformer(); 038 assertEquals(expected, t.transform(input), 1.0e-4); 039 } 040 041 /** 042 * 043 */ 044 public void testTransformNull(){ 045 DefaultTransformer t = new DefaultTransformer(); 046 try { 047 t.transform(null); 048 fail("Expection MathException"); 049 } catch (MathException e) { 050 // expected 051 } 052 } 053 054 /** 055 * 056 */ 057 public void testTransformInteger() throws Exception { 058 double expected = 1.0; 059 Integer input = Integer.valueOf(1); 060 DefaultTransformer t = new DefaultTransformer(); 061 assertEquals(expected, t.transform(input), 1.0e-4); 062 } 063 064 /** 065 * 066 */ 067 public void testTransformBigDecimal() throws Exception { 068 double expected = 1.0; 069 BigDecimal input = new BigDecimal("1.0"); 070 DefaultTransformer t = new DefaultTransformer(); 071 assertEquals(expected, t.transform(input), 1.0e-4); 072 } 073 074 /** 075 * 076 */ 077 public void testTransformString() throws Exception { 078 double expected = 1.0; 079 String input = "1.0"; 080 DefaultTransformer t = new DefaultTransformer(); 081 assertEquals(expected, t.transform(input), 1.0e-4); 082 } 083 084 /** 085 * 086 */ 087 public void testTransformObject(){ 088 Boolean input = Boolean.TRUE; 089 DefaultTransformer t = new DefaultTransformer(); 090 try { 091 t.transform(input); 092 fail("Expecting MathException"); 093 } catch (MathException e) { 094 // expected 095 } 096 } 097 098 public void testSerial() { 099 assertEquals(new DefaultTransformer(), TestUtils.serializeAndRecover(new DefaultTransformer())); 100 } 101 102 }