In mathematics, the four colour theorem is a proposition that states that it is possible to colour any land map in which the countries form one unit (without the exclaves) using only four colours without giving two neighbouring countries the same colour. Here, two countries are neighbouring if they have a boundary in common, not if they are only connected by one point. You will see below that this isn't possible when using less than four colours. Luxemburg, Germany, France and Belgium are all neighbouring countries, so at least four colours are needed.

luxemburg

Assignment

Define a class CountryMap which can be used to represent coloured maps. The objects of this class must contain at least the following methods:

When teh name of a country is given as an argument to a method, the method must verify whether that name occurs in the list of countries from the first text file that was given when making the object of the class CountryMap. If this isn't the case, the method should raise an AssertionError with the text unknown country.

Example

In the example session below, we assume that the text files colours1.txt1, colours2.txt2 and neighbouringcountries.txt3 are situated in the current directory.

>>> countrymap = CountryMap('colours1.txt', 'neighbouringcountries.txt')
>>> countrymap.numberCountries()
208
>>> countrymap.numberColours()
5
>>> countrymap.colour('Belgium')
'rood'
>>> countrymap.neighbours('Belgium')
{'Netherlands', 'Germany', 'Luxembourg', 'France'}
>>> countrymap.areNeighbours('Belgium', 'Germany')
True
>>> countrymap.areNeighbours('Belgium', 'Italy')
False
>>> countrymap.invalidNeighbours()
[]

>>> countrymap = CountryMap('kleuren2.txt', 'buurlanden.txt')
>>> countrymap.invalidNeighbours()
[('Angola', 'Democratic Republic of the Congo', 'blauw'), ('Democratic Republic of the Congo', 'Uganda', 'blauw')]

>>> countrymap.colour('Oz')
Traceback (most recent call last):
AssertionError: unknown country
>>> countrymap.neighbours('Oz')
Traceback (most recent call last):
AssertionError: unknown country
>>> countrymap.areNeighbours('Belgium', 'Oz')
Traceback (most recent call last):
AssertionError: unknown country
>>> countrymap.areNeighbours('Oz', 'Belgium')
Traceback (most recent call last):
AssertionError: unknown country