'Check that the mapping is valid.'

def testMapping(self):

    m = master.DataMaster(7000, self.mock_service)
    self.assertNotEqual(m, None)
    server1 = m.RegisterServer(self.host, 7001)
    server2 = m.RegisterServer(self.host, 7002)
    server3 = m.RegisterServer(self.host, 3000)
    self.assertTrue(m.AllRegistered())
    mapping = m.LoadMapping()
    self.assertNotEqual(mapping, None)
    self.assertEqual(mapping.num_servers, 4)
    self.assertEqual(len(mapping.servers), 4)
    self.assertEqual(mapping.servers[0].address, self.host)
    self.assertEqual(mapping.servers[0].port, 7000)
    self.assertEqual(mapping.servers[0].index, 0)
    for (idx, server) in [(1, server1), (2, server2), (3, server3)]:
        self.assertEqual(mapping.servers[idx].address, server.Address())
        self.assertEqual(mapping.servers[idx].port, server.Port())
        self.assertEqual(mapping.servers[idx].index, server.Index())
        self.assertTrue(server.IsRegistered())
    interval1 = server1.Interval()
    interval2 = server2.Interval()
    interval3 = server3.Interval()
    self.assertEqual(interval1.end, interval2.start)
    self.assertEqual(interval2.end, interval3.start)
    self.assertEqual((interval1.end - interval1.end), (interval2.end - interval2.end))
    self.assertEqual((interval1.end - interval1.end), (interval3.end - interval3.end))
    self.assertEqual(interval3.end, constants.MAX_RANGE)
    self.assertEqual(utils._FindServerInMapping(mapping, 0), 0)
    self.assertEqual(utils._FindServerInMapping(mapping, (constants.MAX_RANGE / 4)), 1)
    self.assertEqual(utils._FindServerInMapping(mapping, ((constants.MAX_RANGE / 4) + 1)), 1)
    self.assertEqual(utils._FindServerInMapping(mapping, (constants.MAX_RANGE / 2)), 2)
    half_fifth = ((constants.MAX_RANGE / 2) + (constants.MAX_RANGE / 5))
    self.assertEqual(utils._FindServerInMapping(mapping, half_fifth), 2)
    self.assertEqual(utils._FindServerInMapping(mapping, ((constants.MAX_RANGE / 4) * 3)), 3)
    self.assertEqual(utils._FindServerInMapping(mapping, constants.MAX_RANGE), 3)
