Greg Malcolm avatar Greg Malcolm committed b6cde7a

Merged github pull request from @Ymbirtt 'Change sets for set operators to be more intuitive'

Comments (0)

Files changed (2)

python2/koans/about_sets.py

     def test_sets_make_keep_lists_unique(self):
         highlanders = ['MacLeod', 'Ramirez', 'MacLeod', 'Matunas',
             'MacLeod', 'Malcolm', 'MacLeod']
-        
+
         there_can_only_be_only_one = set(highlanders)
 
         self.assertEqual(__, there_can_only_be_only_one)
 
     def test_sets_are_unordered(self):
         self.assertEqual(set([__, __, __, __, __]), set('12345'))
-        
+
     def test_convert_the_set_into_a_list_to_sort_it(self):
         self.assertEqual(__, sorted(set('13245')))
-        
+
     # ------------------------------------------------------------------
 
-    def chars_in(self, a_set):
-        return ''.join(sorted(a_set))
+    def test_set_have_arithmetic_operators(self):
+        scotsmen = set(['MacLeod', 'Wallace', 'Willie'])
+        warriors = set(['MacLeod', 'Wallace', 'Leonidas'])
 
-    def test_set_have_arithmetic_operators(self):
-        good_guy = set('macleod')
-        bad_guy = set('mutunas')
-        
-        self.assertEqual(__, self.chars_in(good_guy - bad_guy))
-        self.assertEqual(__, self.chars_in(good_guy | bad_guy))
-        self.assertEqual(__, self.chars_in(good_guy & bad_guy))
-        self.assertEqual(__, self.chars_in(good_guy ^ bad_guy))
+        self.assertEqual(__, scotsmen - warriors)
+        self.assertEqual(__, scotsmen | warriors)
+        self.assertEqual(__, scotsmen & warriors)
+        self.assertEqual(__, scotsmen ^ warriors)
 
     # ------------------------------------------------------------------
 
     def test_we_can_query_set_membership(self):
         self.assertEqual(__, 127 in set([127, 0, 0, 1]))
         self.assertEqual(__, 'cow' not in set('apocalypse now'))
-        
+
     def test_we_can_compare_subsets(self):
         self.assertEqual(__, set('cake') <= set('cherry cake'))
         self.assertEqual(__, set('cake').issubset(set('cherry cake')))
-        
+
         self.assertEqual(__, set('cake') > set('pie'))

python3/koans/about_sets.py

 class AboutSets(Koan):
     def test_sets_make_keep_lists_unique(self):
         highlanders = ['MacLeod', 'Ramirez', 'MacLeod', 'Matunas', 'MacLeod', 'Malcolm', 'MacLeod']
-        
+
         there_can_only_be_only_one = set(highlanders)
 
         self.assertEqual(__, there_can_only_be_only_one)
 
         self.assertEqual(__, type({1, 2, 3}).__name__)
         self.assertEqual(__, type({'one': 1, 'two': 2}).__name__)
-        
+
         self.assertEqual(__, type({}).__name__)
 
     def test_creating_sets_using_strings(self):
 
     def test_convert_the_set_into_a_list_to_sort_it(self):
         self.assertEqual(__, sorted(set('12345')))
-        
+
     # ------------------------------------------------------------------
 
-    def chars_in(self, a_set):
-        return ''.join(sorted(a_set))
+    def test_set_have_arithmetic_operators(self):
+        scotsmen = {'MacLeod', 'Wallace', 'Willie'}
+        warriors = {'MacLeod', 'Wallace', 'Leonidas'}
 
-    def test_set_have_arithmetic_operators(self):
-        good_guy = set('macleod')
-        bad_guy = set('mutunas')
-        
-        self.assertEqual(__, self.chars_in( good_guy - bad_guy) )
-        self.assertEqual(__, self.chars_in( good_guy | bad_guy ))       
-        self.assertEqual(__, self.chars_in( good_guy & bad_guy ))
-        self.assertEqual(__, self.chars_in( good_guy ^ bad_guy ))
+        self.assertEqual(__, scotsmen - warriors)
+        self.assertEqual(__, scotsmen | warriors)
+        self.assertEqual(__, scotsmen & warriors)
+        self.assertEqual(__, scotsmen ^ warriors)
 
     # ------------------------------------------------------------------
 
     def test_we_can_query_set_membership(self):
         self.assertEqual(__, 127 in {127, 0, 0, 1} )
         self.assertEqual(__, 'cow' not in set('apocalypse now') )
-        
+
     def test_we_can_compare_subsets(self):
         self.assertEqual(__, set('cake') <= set('cherry cake'))
         self.assertEqual(__, set('cake').issubset(set('cherry cake')) )
-        
+
         self.assertEqual(__, set('cake') > set('pie'))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.