def test_ChargeInfo(): trivial = charges.ChargeInfo() trivial.test_sanity() print("trivial: ", trivial) assert trivial.qnumber == 0 chinfo = charges.ChargeInfo([3, 1], ['some', '']) print("nontrivial chinfo: ", chinfo) assert chinfo.qnumber == 2 qs = [[0, 2], [2, 0], [5, 3], [-2, -3]] is_valid = [True, True, False, False] for q, expect in zip(qs, is_valid): check = chinfo.check_valid(np.array([q], dtype=charges.QTYPE)) assert check == expect qs_valid = np.array([chinfo.make_valid(q) for q in qs]) npt.assert_equal(qs_valid, chinfo.make_valid(qs)) chinfo2 = charges.ChargeInfo([3, 1], ['some', '']) assert (chinfo2 == chinfo) chinfo3 = charges.ChargeInfo([3, 1], ['other', '']) assert (chinfo3 != chinfo)
def test_ChargeInfo(): trivial = charges.ChargeInfo() trivial.test_sanity() print("trivial: ", trivial) nst.eq_(trivial.qnumber, 0) chinfo = charges.ChargeInfo([3, 1], ['some', '']) print("nontrivial chinfo: ", chinfo) nst.eq_(chinfo.qnumber, 2) qs = [[0, 2], [2, 0], [5, 3], [-2, -3]] is_valid = [True, True, False, False] for q, valid in zip(qs, is_valid): print(q, valid) check = chinfo.check_valid(np.array([q])) print(check) nst.eq_(check, valid) qs_valid = np.array([chinfo.make_valid(q) for q in qs]) npt.assert_equal(qs_valid, chinfo.make_valid(qs)) chinfo2 = charges.ChargeInfo([3, 1], ['some', '']) assert (chinfo2 == chinfo) chinfo3 = charges.ChargeInfo([3, 1], ['other', '']) assert (chinfo3 != chinfo)
# sorted qflat_s = np.sort(qflat_us, axis=0) slices_s = np.array([0, 3, 10, 24, 39, 53, 59, 61]) charges_s = np.array([[-6], [-4], [-2], [0], [2], [4], [6]]) qdict_s = { (-6, ): slice(0, 3), (-4, ): slice(3, 10), (-2, ): slice(10, 24), (0, ): slice(24, 39), (2, ): slice(39, 53), (4, ): slice(53, 59), (6, ): slice(59, 61) } ch_1 = charges.ChargeInfo([1]) def test_ChargeInfo(): trivial = charges.ChargeInfo() trivial.test_sanity() print("trivial: ", trivial) assert trivial.qnumber == 0 chinfo = charges.ChargeInfo([3, 1], ['some', '']) print("nontrivial chinfo: ", chinfo) assert chinfo.qnumber == 2 qs = [[0, 2], [2, 0], [5, 3], [-2, -3]] is_valid = [True, True, False, False] for q, expect in zip(qs, is_valid): check = chinfo.check_valid(np.array([q], dtype=charges.QTYPE)) assert check == expect