From: SourceForge.net <no...@so...> - 2008-01-04 10:38:24
|
Feature Requests item #1762410, was opened at 2007-07-27 22:55 Message generated for change (Comment added) made by bodewig You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1762410&group_id=23187 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Ken Estes (kestesisme) Assigned to: Nobody/Anonymous (nobody) Summary: use tolerance for floating point values in XML Initial Comment: We produce XML which has numerical values scattered through out the XML both in nodes and attributes. <svg xmlns="http://www.w3.org/2000/svg" width="0.085in" height="0.085in"> <text text-anchor="end" y="92" x="15">36</text> <fo:block-container height="2pc" width="46.5pc" left="2.5pc" top="64pc"> The numerical values can be produced by computations which are carried out in software or hardware. Because of round off errors we need to have a custom string equals function which will allow for round off in the numeric portions of the string. Enclosed please find a file which will perform such numeric comparisons. Here is my suggestion for how to hook it into XMLUnit. /** * Test two non-null values for inequality * @param expected * @param actual * @return TRUE if the values are not equals() equal (taking whitespace * into account if necessary) */ private boolean unequalNotNull(Object expected, Object actual) { boolean bothStrings = (expected instanceof String && actual instanceof String); if (!bothStrings) { return !(expected.equals(actual)); } String expectedString = (String) expected; String actualString = (String) actual; if (XMLUnit.getIgnoreWhitespace()) { expectedString = expected.trim(); actualString = actual.trim(); } if (XMLUnit.getNormalizeWhitespace()) { expectedString = normalizeWhitespace(expectedString); actualString = normalizeWhitespace(actualString); } if (XMLUnit.getTolerantNumericCompare) { return !StringCmpNumericTolerance.equals(expected,actualString); } return !expectedString.equals(actualString); } ---------------------------------------------------------------------- >Comment By: Stefan Bodewig (bodewig) Date: 2008-01-04 11:38 Message: Logged In: YES user_id=113148 Originator: NO Hi Ken, to be honest I feel we would be stretching XMLUnit quite a bit if we added special purpose options like handling of numeric values to its core. The same could be said for case insensitive comparisons of element and attribute names (HTML as a use-case) or texts and so on. It should be possible to use a DifferenceListener of your own that wrapped whatever DifferenceListener would get used normally and performed some special sort of comparision for ATTR_VALUE Differences. We might even add such a DifferenceListener in XMLUnit's examples package. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=377771&aid=1762410&group_id=23187 |