From 74dd68ad611d15abf16a65c36a7cfd3f4492930a Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 9 Nov 2012 16:25:22 +0000 Subject: Made the repo less libbu++-centric. --- c++-libbu++/src/unit/float.unit | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 c++-libbu++/src/unit/float.unit (limited to 'c++-libbu++/src/unit/float.unit') diff --git a/c++-libbu++/src/unit/float.unit b/c++-libbu++/src/unit/float.unit new file mode 100644 index 0000000..b1eb063 --- /dev/null +++ b/c++-libbu++/src/unit/float.unit @@ -0,0 +1,84 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2010 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "gats/dictionary.h" +#include "gats/float.h" +#include "gats/string.h" + +#include "bu/membuf.h" +#include "bu/list.h" +#include "bu/sio.h" + +#include +#include + +using namespace Bu; + +suite Basic +{ + void rw( double dVal ) + { + Bu::MemBuf mb; + + Gats::Float( dVal ).write( mb ); + + mb.setPos( 0 ); + + Gats::Object *pObj = Gats::Object::read( mb ); + unitTest( pObj != NULL ); + unitTest( pObj->getType() == Gats::typeFloat ); + Gats::Float *pFlt = dynamic_cast(pObj); + Bu::String sHex; + for( Bu::String::iterator i = mb.getString().begin(); i; i++ ) + { + sHex += "0123456789abcdef"[(((uint8_t)*i)>>4)&0x0f]; + sHex += "0123456789abcdef"[(*i)&0x0f]; + sHex += ' '; + } + printf("In: %a\nOut: %a\nRaw: %s\n", dVal, pFlt->getValue(), sHex.getStr() ); + if( isnan( dVal ) ) + unitTest( isnan(pFlt->getValue()) == isnan(dVal) ); + else + unitTest( pFlt->getValue() == dVal ); + unitTest( signbit(pFlt->getValue()) == signbit(dVal) ); + + delete pObj; + } + + test positive + { + rw( 8485738457.0 ); + rw( 63723.0 ); + rw( 0.000000000000001928173 ); + rw( 1.0 ); + rw( 0.0 ); + rw( M_PI ); + } + + test negitave + { + rw( -8485738457.0 ); + rw( -63723.0 ); + rw( -0.000000000000001928173 ); + rw( -1.0 ); + rw( -0.0 ); + rw( -M_PI ); + } + + test inf + { + rw( INFINITY ); + rw( -INFINITY ); + } + + test nan + { + rw( NAN ); + rw( -NAN ); + } +} -- cgit v1.2.3