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

#
# Based on AboutHashes in the Ruby Koans
#

from runner.koan import *


class AboutDictionaries(Koan):
    def test_creating_dictionaries(self):
        empty_dict = dict()
        self.assertEqual(dict, type(empty_dict))
        self.assertEqual(dict(), empty_dict)
        self.assertEqual(__, len(empty_dict))

    def test_dictionary_literals(self):
        empty_dict = {}
        self.assertEqual(dict, type(empty_dict))
        babel_fish = {'one': 'uno', 'two': 'dos'}
        self.assertEqual(__, len(babel_fish))

    def test_accessing_dictionaries(self):
        babel_fish = {'one': 'uno', 'two': 'dos'}
        self.assertEqual(__, babel_fish['one'])
        self.assertEqual(__, babel_fish['two'])

    def test_changing_dictionaries(self):
        babel_fish = {'one': 'uno', 'two': 'dos'}
        babel_fish['one'] = 'eins'

        expected = {'two': 'dos', 'one': __}
        self.assertEqual(expected, babel_fish)

    def test_dictionary_is_unordered(self):
        dict1 = {'one': 'uno', 'two': 'dos'}
        dict2 = {'two': 'dos', 'one': 'uno'}

        self.assertEqual(____, dict1 == dict2)

    def test_dictionary_keys_and_values(self):
        babel_fish = {'one': 'uno', 'two': 'dos'}
        self.assertEqual(__, len(babel_fish.keys()))
        self.assertEqual(__, len(babel_fish.values()))
        self.assertEqual(__, 'one' in babel_fish.keys())
        self.assertEqual(__, 'two' in babel_fish.values())
        self.assertEqual(__, 'uno' in babel_fish.keys())
        self.assertEqual(__, 'dos' in babel_fish.values())

    def test_making_a_dictionary_from_a_sequence_of_keys(self):
        cards = {}.fromkeys(
            ('red warrior', 'green elf', 'blue valkyrie', 'yellow dwarf',
             'confused looking zebra'),
            42)

        self.assertEqual(__, len(cards))
        self.assertEqual(__, cards['green elf'])
        self.assertEqual(__, cards['yellow dwarf'])

@@ -330,26 +330,25 @@
 assertEqual(
-__
+0
 , len(empty_
@@ -436,36 +436,44 @@
 elf.assertEqual(
+type(
 dict
+())
 , type(empty_dic
@@ -543,34 +543,33 @@
 elf.assertEqual(
-__
+2
 , len(babel_fish
@@ -682,34 +682,37 @@
 elf.assertEqual(
-__
+'uno'
 , babel_fish%5B'on
@@ -741,18 +741,21 @@
 rtEqual(
-__
+'dos'
 , babel_
@@ -937,18 +937,22 @@
  'one': 
-__
+'eins'
 %7D%0A      
@@ -1157,12 +1157,12 @@
 ual(
-____
+True
 , di
@@ -1290,34 +1290,33 @@
 elf.assertEqual(
-__
+2
 , len(babel_fish
@@ -1346,26 +1346,25 @@
 assertEqual(
-__
+2
 , len(babel_
@@ -1404,18 +1404,20 @@
 rtEqual(
-__
+True
 , 'one' 
@@ -1463,18 +1463,21 @@
 rtEqual(
-__
+False
 , 'two' 
@@ -1525,18 +1525,21 @@
 rtEqual(
-__
+False
 , 'uno' 
@@ -1585,18 +1585,20 @@
 rtEqual(
-__
+True
 , 'dos' 
@@ -1871,18 +1871,17 @@
 rtEqual(
-__
+5
 , len(ca
@@ -1903,34 +1903,34 @@
 elf.assertEqual(
-__
+42
 , cards%5B'green e
@@ -1964,10 +1964,10 @@
 ual(
-__
+42
 , ca

solve about_dictionaries