1#!/usr/bin/env python
2# Copyright 2009 Google Inc. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16"""Tests for NameBench and basic methods."""
17
18__author__ = 'tstromberg@google.com (Thomas Stromberg)'
19
20import datetime
21import util
22import unittest
23
24
25class TestBasicMethods(unittest.TestCase):
26  def testTimeDeltaToMilliseconds(self):
27    delta = datetime.timedelta(days=1)
28    self.assertEqual(util.TimeDeltaToMilliseconds(delta), 86400000)
29
30    delta = datetime.timedelta(0, 3, 248193)
31    self.assertEqual(util.TimeDeltaToMilliseconds(delta),
32                     3248.1930000000002)
33
34  def testCalculateListAverage(self):
35    self.assertEqual(util.CalculateListAverage([3, 2, 2]),
36                     2.3333333333333335)
37
38  def testDrawTextBar(self):
39    self.assertEqual(util.DrawTextBar(1, 10, max_width=10), '#')
40    self.assertEqual(util.DrawTextBar(5, 10, max_width=10), '#####')
41    self.assertEqual(util.DrawTextBar(5, 5, max_width=5), '#####')
42    # Make sure to draw at least something!
43    self.assertEqual(util.DrawTextBar(0.05, 10, max_width=10), '#')
44
45  def testInternalNameServers(self):
46    self.assertTrue(len(util.InternalNameServers()) > 0)
47    self.assertTrue(len(util.InternalNameServers()) < 5)
48
49
50
51if __name__ == '__main__':
52  unittest.main()
53