Skip to content

Commit 9ccf7f1

Browse files
committed
Merge pull request faif#131 from fkromer/test_flyweight
tests for flyweight.py
2 parents 79deb88 + 529c76f commit 9ccf7f1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

test_flyweight.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from flyweight import Card
5+
from sys import version_info
6+
7+
if version_info < (2, 7):
8+
import unittest2 as unittest
9+
else:
10+
import unittest
11+
12+
class TestCard(unittest.TestCase):
13+
14+
def test_instances_shall_reference_same_object(self):
15+
c1 = Card('9', 'h')
16+
c2 = Card('9', 'h')
17+
self.assertEqual(c1, c2)
18+
self.assertEqual(id(c1), id(c2))
19+
20+
def test_instances_with_different_suit_shall_reference_different_objects(self):
21+
c1 = Card('9', 'a')
22+
c2 = Card('9', 'b')
23+
self.assertNotEqual(id(c1), id(c2))
24+
25+
def test_instances_with_different_values_shall_reference_different_objects(self):
26+
c1 = Card('9', 'h')
27+
c2 = Card('A', 'h')
28+
self.assertNotEqual(id(c1), id(c2))
29+
30+
def test_instances_shall_share_additional_attributes(self):
31+
expected_attribute_name = 'attr'
32+
expected_attribute_value = 'value of attr'
33+
c1 = Card('9', 'h')
34+
c1.attr = expected_attribute_value
35+
c2 = Card('9', 'h')
36+
self.assertEqual(hasattr(c2, expected_attribute_name), True)
37+
self.assertEqual(c2.attr, expected_attribute_value)
38+
39+
if __name__ == "__main__":
40+
unittest.main()
41+

0 commit comments

Comments
 (0)