forked from faif/python-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_flyweight.py
38 lines (32 loc) · 1.12 KB
/
test_flyweight.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from structural.flyweight import Card
class TestCard(unittest.TestCase):
def test_instances_shall_reference_same_object(self):
c1 = Card('9', 'h')
c2 = Card('9', 'h')
self.assertEqual(c1, c2)
self.assertEqual(id(c1), id(c2))
def test_instances_with_different_suit(self):
"""
shall reference different objects
"""
c1 = Card('9', 'a')
c2 = Card('9', 'b')
self.assertNotEqual(id(c1), id(c2))
def test_instances_with_different_values(self):
"""
shall reference different objects
"""
c1 = Card('9', 'h')
c2 = Card('A', 'h')
self.assertNotEqual(id(c1), id(c2))
def test_instances_shall_share_additional_attributes(self):
expected_attribute_name = 'attr'
expected_attribute_value = 'value of attr'
c1 = Card('9', 'h')
c1.attr = expected_attribute_value
c2 = Card('9', 'h')
self.assertEqual(hasattr(c2, expected_attribute_name), True)
self.assertEqual(c2.attr, expected_attribute_value)