Ejemplo n.º 1
0
    def test_save_load(self):
        hist = Histogram()
        self.addCleanup(self._del_table, "histograms")
        hist.create_table(self._db)

        hist.calculate([1, 2, 3, 3, 5], 1)

        data_id = hist.store(self._db, 1, "MyHist")
        hist = None
        hist_new = Histogram()
        hist_new.load(self._db, 1, "MyHist")
        self.assertEqual(hist_new._get("edges"), [1, 2, 3, 4, 5, 6])
        self.assertEqual(list(hist_new._get("bins")), [0.2, 0.2, 0.4, 0, 0.2])
Ejemplo n.º 2
0
    def test_calculate(self):
        hist = Histogram()

        hist.calculate([1, 2, 3, 3, 5], 1)
        bins, edges = hist.get_data()
        self.assertEqual(edges, [1, 2, 3, 4, 5, 6])
        self.assertEqual(list(bins), [0.2, 0.2, 0.4, 0, 0.2])

        hist.calculate([1, 2, 3, 3, 5], 1, minmax=(1, 3))
        self.assertEqual(hist._get("edges"), [1, 2, 3, 4])
        self.assertEqual(list(hist._get("bins")), [0.25, 0.25, 0.5])

        hist.calculate([1, 2, 3, 3, 5], 1, minmax=(1, 3), input_bins=[1, 6])
        self.assertEqual(hist._get("edges"), [1, 6])
        self.assertEqual(list(hist._get("bins")), [1.0])