Monday, December 20, 2010

Unit Testing Precision Inferrence

I am currently implementing section 4.6.6 of the XBRL spec ("Inferring Precision") as a part of my overall effort to add support for an XBRL item's precision and decimals attributes to Gepsio. This section of the spec contains a very nice table in Example 13 that provides examples of sample fact values, decimals attribute values, and the calculated value of the inferred precision for the fact. Since the XBRL-CONF-CR3-2007-03-05 conformance suite doesn't provide test coverage specifically for the values in this table, I have implemented specific unit tests for Gepsio to cover each row in the Example 13 table.

I have created a sample XBRL document for each row of the table, and each row has a corresponding unit test. For example, the first row of the Example 13 table states that a fact value of 123 and a decimals attribute of 2 should carry and implied precision of 5. To test this, I created an XBRL document containing this value as a fact:

<?xml version="1.0" encoding="utf-8"?>
<xbrl
  xmlns="
http://www.xbrl.org/2003/instance"
  xmlns:link="
http://www.xbrl.org/2003/linkbase"
  xmlns:xlink="
http://www.w3.org/1999/xlink"
  xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
  xmlns:iso4217="
http://www.xbrl.org/2003/iso4217"
  xmlns:inferprecisiontestcase="
http://gepsio.codeplex.com/InferPrecisionTest">
  <link:schemaRef xlink:href="Example13.xsd" xlink:type="simple" />
  <context id="context">
    <entity>
      <identifier scheme="
http://gepsio.codeplex.com">entity</identifier>
    </entity>
    <period>
      <instant>2006-07-28</instant>
    </period>
  </context>
  <unit id="unit">
    <measure>iso4217:EUR</measure>
  </unit>
  <inferprecisiontestcase:A contextRef="context" unitRef="unit" decimals="2">123</inferprecisiontestcase:A>
</xbrl>


This sample document is associated with an appropriate schema:

<?xml version="1.0" encoding="utf-8"?>
<schema
  xmlns="
http://www.w3.org/2001/XMLSchema"
  xmlns:xbrli="
http://www.xbrl.org/2003/instance"
  xmlns:link="
http://www.xbrl.org/2003/linkbase"
  xmlns:xlink="
http://www.w3.org/1999/xlink"
  xmlns:inferprecisiontestcase="
http://gepsio.codeplex.com/InferPrecisionTest"
  targetNamespace="
http://gepsio.codeplex.com/InferPrecisionTest"
  elementFormDefault="qualified"
  attributeFormDefault="unqualified">
  <import namespace="
http://www.xbrl.org/2003/instance" schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd" />
  <element id="calcinferprecisiontestcase_A" name="A" type="xbrli:monetaryItemType" substitutionGroup="xbrli:item" xbrli:periodType="instant" nillable="true" />
</schema>


The unit test simply loads this XBRL document, looks for the document's fact, and checks the fact's properties to ensure that the correct values are available:

        [TestMethod]
        public void Example13Row1()
        {
            XbrlDocument NewXbrlDocument = new XbrlDocument();
            NewXbrlDocument.Load(@"..\..\..\JeffFerguson.Test.Gepsio\InferPrecisionTestDocuments\Example13Row1.xbrl");
            Assert.AreEqual<int>(1, NewXbrlDocument.XbrlFragments.Count, "No XBRL fragments found.");
            XbrlFragment FirstFragment = NewXbrlDocument.XbrlFragments[0];
            Assert.AreEqual<int>(1, FirstFragment.Facts.Count, "No facts found in fragment.");
            Fact FirstFact = FirstFragment.Facts[0];
            Assert.IsTrue(FirstFact.DecimalsSpecified);
            Assert.IsFalse(FirstFact.PrecisionSpecified);
            Assert.IsTrue(FirstFact.PrecisionInferred);
            Assert.AreEqual<int>(5, FirstFact.Precision);
        }


I will follow this pattern for every row in the Example table to ensure that there is adequate test coverage for Gepsio's calculation of inferred precision values for a fact.

These tests leverage a new Fact property called PrecisionInferred, which will be available in the next build.

No comments:

Post a Comment