1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4#
5# Copyright 2017, Data61
6# Commonwealth Scientific and Industrial Research Organisation (CSIRO)
7# ABN 41 687 119 230.
8#
9# This software may be distributed and modified according to the terms of
10# the BSD 2-Clause license. Note that NO WARRANTY is provided.
11# See "LICENSE_BSD2.txt" for details.
12#
13# @TAG(DATA61_BSD)
14#
15
16from __future__ import absolute_import, division, print_function, \
17    unicode_literals
18
19import os, six, subprocess, sys, unittest
20
21ME = os.path.abspath(__file__)
22
23# Make CAmkES importable
24sys.path.append(os.path.join(os.path.dirname(ME), '../../..'))
25
26from camkes.internal.tests.utils import CAmkESTest, python_available
27
28class TestHashingAssumptions(CAmkESTest):
29    '''
30    Some hashing operations we perform in the AST, and on-disk caching that we
31    go on to perform, relies on the hashes of certain objects being stable
32    across executions. It's not clear to me from the Python documentation
33    whether hashing of built-in types actually has the properties we need, so
34    this test case validates our assumptions.
35    '''
36
37    def test_int(self):
38        '''
39        Test the hash of an `int` is just its value, which we expect.
40        '''
41        for i in six.moves.range(1000):
42            self.assertEqual(i, hash(i),
43                'hash of %d is not %d as expected' % (i, i))
44
45    def test_bool(self):
46        '''
47        Test the hash of a `bool` is its integer value as expected.
48        '''
49        self.assertEqual(hash(True), 1)
50        self.assertEqual(hash(False), 0)
51
52if __name__ == '__main__':
53    unittest.main()
54