コード例 #1
0
    def test_round_value(self):
        val_str, unc_strs, mag = round_value(1.23, 0.456)
        self.assertEqual(val_str, "123")
        self.assertEqual(tuple(unc_strs), ("46", ))
        self.assertEqual(mag, -2)

        num = Number(1.23, 0.456)
        val_str, unc_strs, mag = round_value(num)
        self.assertEqual(val_str, "123")
        self.assertEqual(tuple(unc_strs), ("46", "46"))
        self.assertEqual(mag, -2)

        with self.assertRaises(ValueError):
            round_value(1.23)
コード例 #2
0
ファイル: __init__.py プロジェクト: riga/scinum
    def test_round_value_numpy(self):
        val_str, unc_strs, mag = round_value(np.array([1.23, 4.56, 10]),
                                             np.array([0.45678, 0.078, 0.998]))
        self.assertEqual(tuple(val_str), (b"1230", b"4560", b"10000"))
        self.assertEqual(tuple(unc_strs[0]), (b"457", b"78", b"998"))
        self.assertEqual(mag, -3)

        val_str, unc_strs, mag = round_value(np.array([1.23, 4.56, 10]), 1)
        self.assertEqual(tuple(val_str), (b"123", b"456", b"1000"))
        self.assertEqual(tuple(unc_strs[0]), (b"100", b"100", b"100"))
        self.assertEqual(mag, -2)

        with self.assertRaises(TypeError):
            round_value(np.array([1.23, 4.56, 10]))
コード例 #3
0
 def test_round_value_numpy(self):
     val_str, unc_strs, mag = round_value(np.array([1.23, 4.56, 10]),
                                          np.array([0.45678, 0.078, 0.998]))
     self.assertEqual(tuple(val_str), ("1230", "4560", "10000"))
     self.assertEqual(tuple(unc_strs[0]), ("457", "78", "998"))
     self.assertEqual(mag, -3)
コード例 #4
0
 def test_round_value_list(self):
     val_str, unc_strs, mag = round_value(1.23, [0.45678, 0.078, 0.998])
     self.assertEqual(val_str, "1230")
     self.assertEqual(tuple(unc_strs[0]), ("457", "78", "998"))
     self.assertEqual(mag, -3)