#!/usr/bin/env python
# -*- coding: utf-8 -*-

from runner.koan import *

class AboutTuples(Koan):
    def test_creating_a_tuple(self):
        count_of_three =  (1, 2, 5)
        self.assertEqual(__, count_of_three[2])

    def test_tuples_are_immutable_so_item_assignment_is_not_possible(self):
        count_of_three =  (1, 2, 5)
        try:
            count_of_three[2] = "three"
        except TypeError as ex:
            msg = ex.args[0]

        # Note, assertRegexpMatches() uses regular expression pattern matching,
        # so you don't have to copy the whole message.

        self.assertRegexpMatches(msg, __)

    def test_tuples_are_immutable_so_appending_is_not_possible(self):
        count_of_three =  (1, 2, 5)
        with self.assertRaises(___): count_of_three.append("boom")

        # Tuples are less flexible than lists, but faster.

    def test_tuples_can_only_be_changed_through_replacement(self):
        count_of_three = (1, 2, 5)

        list_count = list(count_of_three)
        list_count.append("boom")
        count_of_three = tuple(list_count)

        self.assertEqual(__, count_of_three)

    def test_tuples_of_one_look_peculiar(self):
        self.assertEqual(__, (1).__class__)
        self.assertEqual(__, (1,).__class__)
        self.assertEqual(__, ("Hello comma!", ))

    def test_tuple_constructor_can_be_surprising(self):
        self.assertEqual(__, tuple("Surprise!"))

    def test_creating_empty_tuples(self):
        self.assertEqual(__ , ())
        self.assertEqual(__ , tuple()) #Sometimes less confusing

    def test_tuples_can_be_embedded(self):
        lat = (37, 14, 6, 'N')
        lon = (115, 48, 40, 'W')
        place = ('Area 51', lat, lon)
        self.assertEqual(__, place)

    def test_tuples_are_good_for_representing_records(self):
        locations = [
            ("Illuminati HQ", (38, 52, 15.56, 'N'), (77, 3, 21.46, 'W')),
            ("Stargate B", (41, 10, 43.92, 'N'), (1, 49, 34.29, 'W')),
        ]

        locations.append( ("Cthulu", (26, 40, 1, 'N'), (70, 45, 7, 'W')) )

        self.assertEqual(__, locations[2][0])
        self.assertEqual(__, locations[0][1][2])




@@ -182,34 +182,33 @@
 elf.assertEqual(
-__
+5
 , count_of_three
@@ -614,18 +614,65 @@
 es(msg, 
-__
+%22'tuple' object does not support item assignment%22
 )%0A%0A    d
@@ -807,11 +807,22 @@
 ses(
-___
+AttributeError
 ): c
@@ -1159,18 +1159,33 @@
 rtEqual(
-__
+(1, 2, 5, 'boom')
 , count_
@@ -1264,26 +1264,27 @@
 assertEqual(
-__
+int
 , (1).__clas
@@ -1313,18 +1313,21 @@
 rtEqual(
-__
+tuple
 , (1,)._
@@ -1361,18 +1361,39 @@
 rtEqual(
-__
+tuple(%5B%22Hello comma!%22%5D)
 , (%22Hell
@@ -1405,16 +1405,32 @@
 ma!%22, ))
+  # instructive!
 %0A%0A    de
@@ -1504,18 +1504,61 @@
 rtEqual(
-__
+('S', 'u', 'r', 'p', 'r', 'i', 's', 'e', '!')
 , tuple(
@@ -1639,18 +1639,23 @@
 rtEqual(
-__
+tuple()
  , ())%0A 
@@ -1678,18 +1678,25 @@
 rtEqual(
-__
+tuple('')
  , tuple
@@ -1896,18 +1896,65 @@
 rtEqual(
-__
+('Area 51', (37, 14, 6, 'N'), (115, 48, 40, 'W'))
 , place)
@@ -2287,34 +2287,40 @@
 elf.assertEqual(
-__
+%22Cthulu%22
 , locations%5B2%5D%5B0
@@ -2347,18 +2347,21 @@
 rtEqual(
-__
+15.56
 , locati
@@ -2374,11 +2374,8 @@
 %5B1%5D%5B2%5D)%0A
-%0A%0A%0A

Complete tuples