]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-decimals.py
2 """Independent Decimal arithmetic oracle, TMDM observations and baseline evidence.
3 Decimal.normalize runs with explicitly sufficient precision, never binary float.
9 import xml
.etree
.ElementTree
as ET
11 root
= pathlib
.Path(__file__
).resolve().parent
.parent
12 report
= json
.loads(pathlib
.Path(sys
.argv
[1]).read_text())
13 assert report
['kind'] == 'decimal-semantic-and-cxtm-evidence' and report
['failed'] == 0
14 assert report
['passed'] == len(report
['checks']) == len(set(report
['checks']))
15 names
= ['occurrence-decimal', 'occurrence-decimal-dot', 'occurrence-decimal-dot-neg',
16 'occurrence-decimal-leading-zeros', 'occurrence-decimal-minus-sign',
17 'occurrence-decimal-plus-sign', 'occurrence-decimal-1.0']
18 values
= ['9.3', '0.3', '-0.3', '0.3', '-9.3', '9.3', '1.0']
19 datatype
= 'http://www.w3.org/2001/XMLSchema#decimal'
20 prefix
= 'https://ctm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/'
21 assert [c
['id'] for c
in report
['cases']] == ['ctm/in/' + n
+ '.ctm' for n
in names
]
22 for c
, value
in zip(report
['cases'], values
):
23 ident
= c
['id']; doc
= c
['documentIRI']; m
= c
['actualObjects']
24 assert c
['ctmSource'].encode() == (root
/ 'vendor/cxtm' / ident
).read_bytes()
25 assert doc
== prefix
+ ident
and c
['status'] == 'pass'
26 assert m
['topicCount'] == len(m
['topics']) == 2 and m
['occurrenceCount'] == 1
27 assert m
['nameCount'] == m
['associationCount'] == 0
28 for ordinal
, (topic
, local
) in enumerate(zip(m
['topics'], ['topic', 'occtype']), 1):
29 assert topic
['ordinal'] == ordinal
and topic
['itemIdentifiers'] == [doc
+ '#' + local
]
30 assert topic
['subjectIdentifiers'] == topic
['subjectLocators'] == []
31 assert m
['topics'][0]['occurrences'] == [dict(value
=value
, datatype
=datatype
, parentTopicOrdinal
=1,
32 typeTopicOrdinal
=2, itemIdentifiers
=[])]
33 assert m
['topics'][1]['occurrences'] == []
34 assert len(report
['lexicalProbes']) == 157
35 for p
in report
['lexicalProbes']:
36 literal
= p
['input'].strip(' \t\r\n')
37 with decimal
.localcontext() as context
:
38 context
.prec
= len(literal
) + 10
39 number
= decimal
.Decimal(literal
)
40 assert number
.is_finite()
41 expected
= '0.0' if number
.is_zero() else format(number
.normalize(), 'f')
42 if '.' not in expected
:
44 assert decimal
.Decimal(expected
) == number
45 assert p
['datatype'] == datatype
46 assert p
['storedValue'] == (expected
if p
['mode'] == 'implicit' else p
['input'])
47 xml
= ET
.fromstring(p
['actualCXTM'])
48 items
= xml
.findall('topic/occurrence')
49 assert len(items
) == 1 and items
[0].findtext('value') == expected
50 assert items
[0].findtext('datatype') == datatype
51 print('DECIMAL-INDEPENDENT-PASS: 7 original sources/model observations; 157 Decimal arithmetic-oracle probes, including 10000-digit components')