001/** 002 * Copyright (c) 2008-2014 Ardor Labs, Inc. 003 * 004 * This file is part of Ardor3D. 005 * 006 * Ardor3D is free software: you can redistribute it and/or modify it 007 * under the terms of its license which may be found in the accompanying 008 * LICENSE file or at <http://www.ardor3d.com/LICENSE>. 009 */ 010 011package com.ardor3d.math; 012 013import static org.junit.Assert.*; 014 015import org.junit.Test; 016 017public class TestFastMath { 018 019 @Test 020 public void testSin() { 021 final double angle = MathUtils.DEG_TO_RAD * 45; 022 assertTrue(Math.abs(FastMath.sin(angle) - Math.sin(angle)) <= FastMath.EPSILON_SIN); 023 } 024 025 @Test 026 public void testCos() { 027 double angle = MathUtils.DEG_TO_RAD * 45; 028 assertTrue(Math.abs(FastMath.cos(angle) - Math.cos(angle)) <= FastMath.EPSILON_COS); 029 angle = MathUtils.DEG_TO_RAD * 135; 030 assertTrue(Math.abs(FastMath.cos(angle) - Math.cos(angle)) <= FastMath.EPSILON_COS); 031 } 032 033 @Test 034 public void testTan() { 035 final double angle = MathUtils.DEG_TO_RAD * 45; 036 assertTrue(Math.abs(FastMath.tan(angle) - Math.tan(angle)) <= FastMath.EPSILON_SIN2COS2); 037 } 038 039 @Test 040 public void testAsin() { 041 final double val = 0.5; 042 assertTrue(Math.abs(FastMath.asin(val) - Math.asin(val)) <= FastMath.EPSILON_ASIN); 043 } 044 045 @Test 046 public void testAcos() { 047 final double val = 0.5; 048 assertTrue(Math.abs(FastMath.acos(val) - Math.acos(val)) <= FastMath.EPSILON_ACOS); 049 } 050 051 @Test 052 public void testAtan() { 053 double val = 1; 054 assertTrue(Math.abs(FastMath.atan(val) - Math.atan(val)) <= FastMath.EPSILON_ATAN); 055 val = 0.5; 056 assertTrue(Math.abs(FastMath.atan(val) - Math.atan(val)) <= FastMath.EPSILON_ATAN); 057 } 058 059 @Test 060 public void testInverseSqrt() { 061 final double val = 173; 062 assertTrue(Math.abs(FastMath.inverseSqrt(val) - 1.0 / Math.sqrt(val)) <= FastMath.EPSILON_SQRT); 063 } 064 065 @Test 066 public void testSqrt() { 067 final double val = 173; 068 assertTrue(Math.abs(FastMath.sqrt(val) - Math.sqrt(val)) <= FastMath.EPSILON_SQRT); 069 } 070 071}