From: <dd...@us...> - 2003-01-31 03:07:26
|
Update of /cvsroot/babylonlib/_SrcPool/Cpp/Samples/Calc/Src In directory sc8-pr-cvs1:/tmp/cvs-serv22770/Cpp/Samples/Calc/Src Modified Files: TsCalc.cpp Log Message: Replaced BOOL with bool Index: TsCalc.cpp =================================================================== RCS file: /cvsroot/babylonlib/_SrcPool/Cpp/Samples/Calc/Src/TsCalc.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TsCalc.cpp 28 Jan 2003 05:42:12 -0000 1.2 --- TsCalc.cpp 31 Jan 2003 03:07:23 -0000 1.3 *************** *** 10,16 **** // Group=Examples ! #include "StdAfx.h" #include "KProgCst.h" ! #include "KString.h" //CString #ifdef _DEBUG --- 10,16 ---- // Group=Examples ! #include "stdafx.h" #include "KProgCst.h" ! #include "KTestLog.h" //TESTENTRY struct #ifdef _DEBUG *************** *** 20,25 **** #endif ! void TestRealConversion(); extern bool TsWriteToView(LPCTSTR lszText); #pragma message ("Compiler option:") --- 20,28 ---- #endif ! bool TestRealConversion(); extern bool TsWriteToView(LPCTSTR lszText); + static TESTENTRY s_logEntry = + {_T("NULL"), _T("KProgCst.h"), false}; + #pragma message ("Compiler option:") *************** *** 43,110 **** bool TestCalculus() { ! TsWriteToView(_T("\tTestCalculus:\r\n")); ! CString strText; double dTest = log(0); ! bool bRes = IsNaN(dTest); ! strText.Format(_T("Is log(0) undefined? %s\r\n"),bRes ? _T("Yes"):_T("No")); ! TsWriteToView((LPCTSTR)strText); ! dTest *= 0.0; ! bRes = IsNaN(dTest); ! strText.Format(_T("Is 0*log(0) undefined? %s\r\n"),bRes ? _T("Yes"):_T("No")); ! TsWriteToView((LPCTSTR)strText); ! //String presentations of NaNs ! dTest = 0; ! dTest = CST_dNaN.dValue; ! strText.Format(_T("Quiet NaN %f\r\n"),dTest); ! TsWriteToView((LPCTSTR)strText); ! dTest = (double)CST_dSNaN; ! strText.Format(_T("Signaling NaN %f\r\n"),dTest); ! TsWriteToView((LPCTSTR)strText); ! dTest = (double)CST_dINF; ! strText.Format(_T("Positive Infinity %f\r\n"),dTest); ! TsWriteToView((LPCTSTR)strText); ! TestRealConversion(); ! return TRUE; } - //TestPoint()------------------------------------------------------ #include "KPoint.h" #include "KPair.h" - static fPOINT ptOldPos(0.0F,0.0F); //Old position /*Test of point functions */ ! void TestPoint(const CPoint& point) { ! TsWriteToView(_T("\tTestPoint:\r\n")); ! fPOINT ptPos(point); float fDeg;//[°] float fMin;//['] float fSec;//["] ! Rad2DegMinSec((float)ptPos.Angle(), fDeg, fMin,fSec); ! ! CString strText; ! strText.Format(_T("Cursor at P(%.2f,%.2f) r=%.2f,angle =%.2f°%.2f'%.2f\"\r\n"), ptPos.x,ptPos.y,ptPos.Distance(),fDeg, fMin,fSec); ! TsWriteToView((LPCTSTR)strText); ! fPOINT ptDistance(ptPos - ptOldPos); //Get difference between points ! strText.Format(_T("Distance between new and old position is %.2f units\r\n"), ! ptDistance.Distance()); ! TsWriteToView((LPCTSTR)strText); ! ptOldPos = ptPos; //Save current position ! //Compare points ! TPair<LONG> P(point.x, point.y); ! bool bRes = P > TPair<LONG>(40,120); ! strText.Format("P(%d,%d) %s x(40,120)\r\n",P.x,P.y,bRes?">":"<="); ! TsWriteToView((LPCTSTR)strText); } //TestRealConversion()--------------------------------------------------------- --- 46,203 ---- bool TestCalculus() { ! TsWriteToView(_T("TestCalculus()\r\n")); ! TCHAR szText[512]; ! double dTest = log(0); ! bool bRes = IsNaN(dTest); //log(0) is defined number ! _stprintf(szText, _T("Is log(0) undefined? %s\r\n"),bRes ? _T("Yes"):_T("No")); ! TsWriteToView(szText); //Output: Is log(0) undefined? No ! if (bRes == false) //Validate result ! { ! dTest *= 0.0; ! bRes = IsNaN(dTest); //0*log(0) is undefined number ! _stprintf(szText, _T("Is 0*log(0) undefined? %s\r\n"),bRes ? _T("Yes"):_T("No")); ! TsWriteToView(szText); //Output: Is 0*log(0) undefined? Yes ! } ! s_logEntry.m_szObjectName = _T("IsNaN()"); ! s_logEntry.m_szFileName = _T("KProgCst.inl"); ! s_logEntry.m_bResult = bRes; ! LogTest(&s_logEntry); + if (bRes == true) //Validate previous result + { + //String presentations of NaNs + dTest = 0; + dTest = CST_dNaN.dValue; + _stprintf(szText,_T("Quiet NaN %f\r\n"),dTest); + TsWriteToView(szText); //Output: Quiet NaN -1.#IND00 + _stprintf(szText,_T("%f"),dTest); + bRes = (_tcsncmp(szText,_T("-1.#IND00"), 9) == 0); + s_logEntry.m_szObjectName = _T("CST_dNaN"); + s_logEntry.m_bResult = bRes; + LogTest(&s_logEntry); ! if (bRes) ! { ! dTest = (double)CST_dSNaN; ! _stprintf(szText,_T("Signaling NaN %f\r\n"),dTest); ! TsWriteToView(szText); //Output: Signaling NaN -1.#INF00 ! _stprintf(szText,_T("%f"),dTest); ! bRes = (_tcsncmp(szText,_T("-1.#INF00"), 9) == 0); ! } ! s_logEntry.m_szObjectName = _T("CST_dSNaN"); ! s_logEntry.m_bResult = bRes; ! LogTest(&s_logEntry); + if (bRes) + { + dTest = (double)CST_dINF; + _stprintf(szText,_T("Positive Infinity %f\r\n"),dTest); + TsWriteToView(szText); //Output: Positive Infinity 1.#INF00 + _stprintf(szText,_T("%f"),dTest); + bRes = (_tcsncmp(szText,_T("1.#INF00"), 8) == 0); + } + s_logEntry.m_szObjectName = _T("CST_dINF"); + s_logEntry.m_bResult = bRes; + LogTest(&s_logEntry); + } ! if (bRes) ! bRes = TestRealConversion(); ! return bRes; } //TestPoint()------------------------------------------------------ #include "KPoint.h" #include "KPair.h" /*Test of point functions */ ! bool TestPoint() { ! TsWriteToView(_T("TestPoint()\r\n")); ! TCHAR szBuff[512]; ! bool bRes = false; ! ! fPOINT ptPos(400, 500); ! fPOINT ptOldPos(0.0F,0.0F); //Old position float fDeg;//[°] float fMin;//['] float fSec;//["] ! Rad2DegMinSec((float)ptPos.Angle(), fDeg, fMin, fSec); ! _stprintf(szBuff,_T("Point at P(%.2f,%.2f) r=%.2f,angle =%.2f°%.2f'%.2f\"\r\n"), ptPos.x,ptPos.y,ptPos.Distance(),fDeg, fMin,fSec); ! TsWriteToView(szBuff); ! bRes = ((fDeg == 51.F) && (fMin == 20.F) && (fSec >= 24.693F) && (fSec < 24.694F) ); ! s_logEntry.m_bResult = bRes; ! s_logEntry.m_szFileName = _T("KMathCst.inl"); ! s_logEntry.m_szObjectName = _T("Rad2DegMinSec()"); ! LogTest(&s_logEntry); ! if (bRes) ! { ! fPOINT ptDistance(ptPos - ptOldPos); //Get difference between points ! double dDistance = ptDistance.Distance(); ! _stprintf(szBuff,_T("Distance between new and old position is %.2f units\r\n"), ! dDistance); ! TsWriteToView(szBuff); ! bRes = ((dDistance >= 640.312) && (dDistance < 640.313)) ; ! } ! ! if (bRes) ! { ! //Compare points ! TPair<LONG> P(240,180); ! bRes = P > TPair<LONG>(40,120); ! _stprintf(szBuff,_T("P(%d,%d) %s x(40,120)\r\n"),P.x,P.y,bRes?">":"<="); ! TsWriteToView(szBuff); ! //Validate comparaison ! bRes = (bRes == true); ! s_logEntry.m_bResult = bRes; ! s_logEntry.m_szFileName = _T("KPair.h"); ! s_logEntry.m_szObjectName = _T("TPair"); ! LogTest(&s_logEntry); ! } ! ! s_logEntry.m_bResult = bRes; ! s_logEntry.m_szFileName = _T("KPoint.h"); ! s_logEntry.m_szObjectName = _T("TPoint"); ! LogTest(&s_logEntry); ! return bRes; } + #ifndef _CONSOLE //GUI Application + static fPOINT ptOldPos(0.0F,0.0F); //Old position + /*Test calculation of the distance between two pointer positions + */ + bool TestPoint(const CPoint& point) + { + TsWriteToView(_T("\tTestPoint:\r\n")); + fPOINT ptPos(point); + + float fDeg;//[°] + float fMin;//['] + float fSec;//["] + Rad2DegMinSec((float)ptPos.Angle(), fDeg, fMin, fSec); + + CString szText; + szText.Format(_T("Cursor at P(%.2f,%.2f) r=%.2f,angle =%.2f°%.2f'%.2f\"\r\n"), + ptPos.x,ptPos.y,ptPos.Distance(),fDeg, fMin,fSec); + TsWriteToView((LPCTSTR)szText); + + fPOINT ptDistance(ptPos - ptOldPos); //Get difference between points + szText.Format(_T("Distance between new and old position is %.2f units\r\n"), + ptDistance.Distance()); + TsWriteToView((LPCTSTR)szText); + + ptOldPos = ptPos; //Save current position + //Compare points + TPair<LONG> P(point.x, point.y); + bool bRes = P > TPair<LONG>(40,120); + szText.Format("P(%d,%d) %s x(40,120)\r\n",P.x,P.y,bRes?">":"<="); + TsWriteToView((LPCTSTR)szText); + } + #endif //GUI Application //TestRealConversion()--------------------------------------------------------- *************** *** 112,127 **** /*Test floating-point conversions */ ! void TestRealConversion() { ! TsWriteToView(_T("\tTestRealConversion:\r\n")); ! CString strText; float fTemp = 273.15F; CFloatIEEE cfTemp(fTemp); ! strText.Format(_T("Temperature = %.2fK = %s%d exp(%d)\r\n"), fTemp, ((cfTemp.iSign < 0) ? _T("-") :_T("+")), cfTemp.lMantissa,cfTemp.iExponent); ! TsWriteToView((LPCTSTR)strText); fTemp = (float)cfTemp; } --- 205,228 ---- /*Test floating-point conversions */ ! bool TestRealConversion() { ! TsWriteToView(_T("\r\nTestRealConversion()\r\n")); ! TCHAR szText[512]; ! bool bRes = false; float fTemp = 273.15F; CFloatIEEE cfTemp(fTemp); ! _stprintf(szText, _T("Temperature = %.2fK = %s%d exp(%d)\r\n"), fTemp, ((cfTemp.iSign < 0) ? _T("-") :_T("+")), cfTemp.lMantissa,cfTemp.iExponent); ! TsWriteToView(szText); ! bRes = ((cfTemp.lMantissa == 561971) && (cfTemp.iExponent == 8)); ! //Typecast test fTemp = (float)cfTemp; + s_logEntry.m_bResult = bRes; + s_logEntry.m_szFileName = _T("KReal4IE.h"); + s_logEntry.m_szObjectName = _T("CFloatIEEE"); + LogTest(&s_logEntry); + return bRes; } *************** *** 129,148 **** /*Test findig the roots of a quadratic equation. */ ! void TestQuadraticEquation() { ! TsWriteToView(_T("\tTestQuadraticEquation:\r\n")); ! CString strText; double dA, dB, dC; //coeficients double dX1, dX2; //roots extern bool funcQuadratic(double a,double b,double c,double& x1,double& x2); dA = 1.; dB = 5.; dC = 0.; ! strText.Format(_T("%.2fX^2 + %.2fX + %.2f = 0 have roots:\r\n"),dA, dB, dC); ! TsWriteToView((LPCTSTR)strText); ! if (funcQuadratic(dA, dB, dC, dX1, dX2)) { ! strText.Format(_T("\tx1=%.2f, x2=%.2f\r\n"),dX1, dX2); } else //Roots are complex numbers --- 230,253 ---- /*Test findig the roots of a quadratic equation. */ ! bool TestQuadraticEquation() { ! TsWriteToView(_T("TestQuadraticEquation()")); ! TCHAR szText[512]; ! bool bRes = false; double dA, dB, dC; //coeficients double dX1, dX2; //roots + const bool ROOTS_REAL = true; + const bool ROOTS_COMPLEX = false; + extern bool funcQuadratic(double a,double b,double c,double& x1,double& x2); dA = 1.; dB = 5.; dC = 0.; ! _stprintf(szText, _T("%.2fX^2 + %.2fX + %.2f = 0 have roots:\r\n"),dA, dB, dC); ! TsWriteToView((LPCTSTR)szText); ! if (bRes = funcQuadratic(dA, dB, dC, dX1, dX2)) { ! _stprintf(szText, _T("\tx1=%.2f, x2=%.2f\r\n"),dX1, dX2); } else //Roots are complex numbers *************** *** 150,164 **** if (!IsNaN(dX2)) { ! strText.Format(_T("\tX1=%.2f + i%.2f\r\n"),dX1, dX2); ! TsWriteToView((LPCTSTR)strText); ! strText.Format(_T("\tX2=%.2f - i%.2f\r\n"),dX1, dX2); } else { ! strText =_T("undefined (divide by zero error)\r\n"); } } ! TsWriteToView((LPCTSTR)strText); } --- 255,277 ---- if (!IsNaN(dX2)) { ! _stprintf(szText, _T("\tX1=%.2f + i%.2f\r\n"),dX1, dX2); ! TsWriteToView((LPCTSTR)szText); ! _stprintf(szText, _T("\tX2=%.2f - i%.2f\r\n"),dX1, dX2); } else { ! _stprintf(szText,_T("undefined (divide by zero error)\r\n")); } } + bRes = ((bRes == ROOTS_REAL) && (dX1 == 0.) && (dX2 == -5.)); ! //TODO: test of complex roots ! TsWriteToView((LPCTSTR)szText); ! s_logEntry.m_bResult = bRes; ! s_logEntry.m_szFileName = _T("KfQuadEq.cpp"); ! s_logEntry.m_szObjectName = _T("funcQuadratic()"); ! LogTest(&s_logEntry); ! ! return bRes; } *************** *** 166,169 **** --- 279,284 ---- /***************************************************************************** * $Log: + * 4 Biblioteka1.3 30/01/2003 9:47:24 PMDarko Write results + * to the test log * 3 Biblioteka1.2 20/01/2003 3:15:29 AMDarko Replaced BOOL * with bool |