From 1e3fdd05e30febe92288da5fa431ba62aa753d76 Mon Sep 17 00:00:00 2001 From: Tom Schierenbeck Date: Wed, 17 Jul 2024 09:21:32 +0200 Subject: [PATCH] Removed flags --- src/random_events/flag.py | 74 --------------------------------------- test/test_flag.py | 25 ------------- 2 files changed, 99 deletions(-) delete mode 100644 src/random_events/flag.py delete mode 100644 test/test_flag.py diff --git a/src/random_events/flag.py b/src/random_events/flag.py deleted file mode 100644 index dc1dfd3..0000000 --- a/src/random_events/flag.py +++ /dev/null @@ -1,74 +0,0 @@ -from __future__ import annotations - -from typing_extensions import Type - -from .sigma_algebra import * -from .utils import get_full_class_name - -from enum import Flag, IntFlag - - -class Set(AbstractCompositeSet, IntFlag): - """ - Experimental flag implementation. - """ - - # int flag overload block - __or__ = IntFlag.__or__ - __and__ = IntFlag.__and__ - __sub__ = IntFlag.__sub__ - __xor__ = IntFlag.__xor__ - __eq__ = IntFlag.__eq__ - __hash__ = IntFlag.__hash__ - __contains__ = IntFlag.__contains__ - - @classmethod - @property - def EMPTY_SET(cls) -> Self: - return cls(0) - - def to_string(self): - return IntFlag.__str__(self) - - def complement_if_empty(self) -> Self: - return ~self.EMPTY_SET - - def intersection_with(self, other: Self) -> Self: - return self & other - - def complement(self) -> Self: - result = self.EMPTY_SET - for element in self.__class__: - if element not in self: - result |= element - return result - - def union_with(self, other: Self) -> Self: - return self | other - - @property - def simple_sets(self) -> SortedSet[AbstractSimpleSet]: - return SimpleSetContainer([element for element in self.__class__ if element in self]) - - def is_empty(self) -> bool: - return self == self.EMPTY_SET - - def __lt__(self, other): - return int(self) < int(other) - - def as_composite_set(self) -> Self: - return self - - def simplify(self) -> Self: - return self - - def new_empty_set(self) -> Self: - raise NotImplementedError("This method should not be called due to Flag operations.") - - def make_disjoint(self) -> Self: - return self - - def to_json(self) -> Dict[str, Any]: - return {**SubclassJSONSerializer.to_json(self), - "simple_set_class": self.simple_sets[0].cls_to_json(), - "simple_set_indices": list(map(lambda item: int(item), self.simple_sets))} diff --git a/test/test_flag.py b/test/test_flag.py deleted file mode 100644 index f1d1312..0000000 --- a/test/test_flag.py +++ /dev/null @@ -1,25 +0,0 @@ -import enum -import unittest - -from random_events.flag import Set - - -# class TestFlag(Set): -# A = enum.auto() -# B = enum.auto() -# C = enum.auto() -# -# -# class FlagTestCase(unittest.TestCase): -# -# def test_intersection(self): -# self.assertEqual(TestFlag.A.intersection_with(TestFlag.B), TestFlag(0)) -# self.assertEqual(TestFlag.A.intersection_with(TestFlag.A), TestFlag.A) -# self.assertTrue(TestFlag(0).intersection_with(TestFlag.A).is_empty()) -# -# def test_invert(self): -# self.assertEqual(TestFlag.A.complement(), TestFlag.B | TestFlag.C) - - -if __name__ == '__main__': - unittest.main()