Testing on the Toilet

October 16, 2008

Floating-Point Comparison If your code manipulates floating-point values, your tests will probably involve floating-point values as well. When comparing floating-point values, checking for equality might lead to unexpected results. Rounding errors can lead to a result that is close to the expected one, but not equal. As a consequence, an assertion might fail when checking for equality of two floating-point quantities even if the program is implemented correctly. The Google C++ Testing Framework provides functions for comparing two floating-point quantities up to a given precision. In C++, you can use the following macros: ASSERT_FLOAT_EQ(expected, actual); ASSERT_DOUBLE_EQ(expected, actual); EXPECT_FLOAT_EQ(expected, actual); EXPECT_DOUBLE_EQ(expected, actual);

In Java, JUnit overloads Assert.assertEquals for floating-point types: assertEquals(float expected, float actual, float delta); assertEquals(double expected, double actual, double delta);

An example (in C++): TEST(SquareRootTest, CorrectResultForPositiveNumbers) { EXPECT_FLOAT_EQ(2.0f, FloatSquareRoot(4.0f)); EXPECT_FLOAT_EQ(23.3333f, FloatSquareRoot(544.44444f)); EXPECT_DOUBLE_EQ(2.0, DoubleSquareRoot(4.0)); EXPECT_DOUBLE_EQ(23.33333333333333, DoubleSquareRoot(544.44444444444444)); // succeeds EXPECT_EQ(2.0, DoubleSquareRoot(4.0)); // fails EXPECT_EQ(23.33333333333333, DoubleSquareRoot(544.44444444444444)); }

More information, discussion, and archives: http://googletesting.blogspot.com Copyright © 2007 Google, Inc. Licensed under a Creative Commons Attribution–ShareAlike 2.5 License (http://creativecommons.org/licenses/by-sa/2.5/).

Floating-Point Comparison

16 Oct 2008 - In Java, JUnit overloads Assert.assertEquals for floating-point types: assertEquals(float expected, float actual, float delta);. assertEquals(double expected, double actual, double delta);. An example (in C++): TEST(SquareRootTest, CorrectResultForPositiveNumbers) {. EXPECT_FLOAT_EQ(2.0f ...

129KB Sizes 3 Downloads 286 Views

Recommend Documents

comparison
I She's os tall as her brother. Is it as good as you expected? ...... 9 The ticket wasn't as expensive as I expected. .. .................... ............ . .. 10 This shirt'S not so ...

comparison
1 'My computer keeps crashing,' 'Get a ......... ' . ..... BORN: WHEN? WHERE? 27.7.84 Leeds. 31.3.84 Leeds. SALARY. £26,000 ...... 6 this job I bad I my last one.

Comparison of Square Comparison of Square-Pixel and ... - IJRIT
Square pixels became the norm because there needed to be an industry standard to avoid compatibility issues over .... Euclidean Spaces'. Information and ...

Comparison Theorem
part), l'Hôpital's rule, and some other tools and the geometric intuition can be illustrated .... Ui(t) := 1. √fi(t0). Ji(t). (3.9) for i = 1, 2. Therefore, by the Jacobi equations and the ... Then define a map ϕ from the set of vector fields alo

SHAKLEE COST COMPARISON
SHAKLEE. COST COMPARISON. Based on Shaklee Member Price. Conventional product prices obtained from Kroger, Athens, GA on May 26, 2007. Green product prices obtained from Earth Fare Natural Supermarket, Athens, GA on May 26, 2007. All comparisons are

Floating-Point Comparison
Oct 16, 2008 - More information, discussion, and archives: http://googletesting.blogspot.com. Copyright © 2007 Google, Inc. Licensed under a Creative ...

Floating-Point Comparison
16 Oct 2008 - In Java, JUnit overloads Assert.assertEquals for floating-point types: assertEquals(float expected, float actual, float delta);. assertEquals(double expected, double actual, double delta);. An example (in C++): TEST(SquareRootTest, Corr

shaklee cost comparison - Health
Cost. Usage per Gallon. Gallons of Solution. Cost per Gallon. Fantastic Heavy .... PDF file to save and print from your computer, send your request by e-mail to ...

College Comparison Worksheet.pdf
COLLEGE COMPARISON WORKSHEET. Page 2 of 2. College Comparison Worksheet.pdf. College Comparison Worksheet.pdf. Open. Extract. Open with.

Pillar Comparison Chart.pdf
Uvulopalato-Pharyngoplasty. (UPPP): surgeon removes excess. tissue in your airway, which may. include the uvula, soft palate,. tonsils, adenoids, and pharynx.

Role Comparison Methodology
To this end, we first provide a general description of the Web Server role, and then describe a typical deployment ... chose the most recent version of Windows server software, Microsoft Windows Server. 2003 and Red Hat ..... was first released on a

comparison pdf software
Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. comparison pdf software. comparison pdf software. Open. Extract.

College Comparison Worksheet.pdf
College Comparison Worksheet.pdf. College Comparison Worksheet.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying College Comparison ...

shaklee cost comparison - WomanWize Health
SHAKLEE. COST COMPARISON ... Cost. Usage per Gallon. Gallons of Solution. Cost per Gallon. Fantastic Heavy Duty .... Use much less packaging materials,.

comparison of techniques
Zircon. Zr [SiO4]. 1 to >10,000. < 2 most. Titanite. CaTi[SiO3](O,OH,F). 4 to 500. 5 to 40 k,c,a,m,ig,mp, gp,hv, gn,sk. Monazite. (Ce,La,Th)PO4. 282 to >50,000. < 2 mp,sg, hv,gp. Xenotime. YPO4. 5,000 to 29,000. < 5 gp,sg. Thorite. Th[SiO4]. > 50,000

Comparison-2.pdf
Five-year moratorium, after which USPS must consider alterna- tives to closings. ... to de- fray costs; waiver for physical hardship; OIG review of savings.

Role Comparison Methodology
Role Comparison Report – Web Server Role. Richard Ford, Ph.D., ... Ave., Melbourne, FL 32904. Tel: (321) 308-0557 Fax (321) 308-0552 .... The corporation may handle credit card information as an online retailer or bank, for example, or be ...

Comparison of Results
Education Programs Office. The authors would also like to ... M.S. Thesis, Virginia Polytechnic Institute and State. University, Blacksburg, Virginia, 2000.

pdf file comparison
File: Pdf file comparison. Download now. Click here if your download doesn't start automatically. Whoops! There was a problem loading this page. Whoops!

Comparison-of-PHP-Frameworks.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item.

Download full comparison (PDF) - G Suite
Groups for Business. Admin managed Groups. Forums and collaborative inboxes. Secure by design. Control access, creation, visibility. Moderate messages ... Voice typing. Supports file types, like Office. Revision history. Action items. Customizable te