示例#1
0
 def test_invert_1(self):
     # maps a number to a number
     x = LinearScale().range([1, 2])
     self.assertAlmostEqual(x.invert(0.5), -0.5)
     self.assertAlmostEqual(x.invert(1), 0)
     self.assertAlmostEqual(x.invert(1.5), 0.5)
     self.assertAlmostEqual(x.invert(2), 1)
     self.assertAlmostEqual(x.invert(2.5), 1.5)
示例#2
0
 def test_invert_1(self):
     # maps a number to a number
     x = LinearScale().range([1, 2])
     self.assertAlmostEqual(x.invert(0.5), -0.5)
     self.assertAlmostEqual(x.invert(1), 0)
     self.assertAlmostEqual(x.invert(1.5), 0.5)
     self.assertAlmostEqual(x.invert(2), 1)
     self.assertAlmostEqual(x.invert(2.5), 1.5)
示例#3
0
    def test_clamp_3(self):
        # can clamp to the range
        x = LinearScale().clamp(True)
        self.assertAlmostEqual(x.invert(-0.5), 0)
        self.assertAlmostEqual(x.invert(0.5), 0.5)
        self.assertAlmostEqual(x.invert(1.5), 1)

        x = LinearScale().range([1, 0]).clamp(True)
        self.assertAlmostEqual(x.invert(-0.5), 1)
        self.assertAlmostEqual(x.invert(0.5), 0.5)
        self.assertAlmostEqual(x.invert(1.5), 0)
示例#4
0
    def test_clamp_3(self):
        # can clamp to the range
        x = LinearScale().clamp(True)
        self.assertAlmostEqual(x.invert(-0.5), 0)
        self.assertAlmostEqual(x.invert(0.5), 0.5)
        self.assertAlmostEqual(x.invert(1.5), 1)

        x = LinearScale().range([1, 0]).clamp(True)
        self.assertAlmostEqual(x.invert(-0.5), 1)
        self.assertAlmostEqual(x.invert(0.5), 0.5)
        self.assertAlmostEqual(x.invert(1.5), 0)
示例#5
0
 def test_copy_2(self):
     # change to the range are isolated
     x = LinearScale()
     y = x.copy()
     x.range([1, 2])
     self.assertEqual(x.invert(1), 0)
     self.assertEqual(y.invert(1), 1)
     self.assertEqual(y.range(), [0, 1])
     y.range([2, 3])
     self.assertEqual(x.invert(2), 1)
     self.assertEqual(y.invert(2), 0)
     self.assertEqual(x.range(), [1, 2])
     self.assertEqual(y.range(), [2, 3])
示例#6
0
 def test_copy_2(self):
     # change to the range are isolated
     x = LinearScale()
     y = x.copy()
     x.range([1, 2])
     self.assertEqual(x.invert(1), 0)
     self.assertEqual(y.invert(1), 1)
     self.assertEqual(y.range(), [0, 1])
     y.range([2, 3])
     self.assertEqual(x.invert(2), 1)
     self.assertEqual(y.invert(2), 0)
     self.assertEqual(x.range(), [1, 2])
     self.assertEqual(y.range(), [2, 3])
示例#7
0
 def test_range_1(self):
     # defaults to [0, 1]
     x = LinearScale()
     self.assertEqual(x.range(), [0, 1])
     self.assertAlmostEqual(x.invert(0.5), 0.5)
示例#8
0
 def test_range_1(self):
     # defaults to [0, 1]
     x = LinearScale()
     self.assertEqual(x.range(), [0, 1])
     self.assertAlmostEqual(x.invert(0.5), 0.5)