コード例 #1
0
ファイル: OTNSTestCase.py プロジェクト: simonlingoogle/ot-ns
class OTNSTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        tracemalloc.start()
        logging.basicConfig(
            level=logging.DEBUG,
            format='%(asctime)-15s - %(levelname)s - %(message)s')

    def setUp(self) -> None:
        self.ns = OTNS(otns_args=['-log', 'debug'])
        self.ns.speed = OTNS.MAX_SIMULATE_SPEED

    def tearDown(self) -> None:
        self.ns.close()

    def assertFormPartitions(self, count: int):
        pars = self.ns.partitions()
        self.assertTrue(len(pars) == count and 0 not in pars, pars)

    def go(self, duration: float) -> None:
        """
        Run the simulation for a given duration.

        :param duration: the duration to simulate
        """
        self.ns.go(duration)

    def assertNodeState(self, nodeid: int, state: str):
        cur_state = self.ns.get_state(nodeid)
        self.assertEqual(
            state, cur_state,
            f"Node {nodeid} state mismatch: expected {state}, but is {cur_state}"
        )
コード例 #2
0
class OTNSTestCase(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        tracemalloc.start()
        logging.basicConfig(level=logging.DEBUG)

    def setUp(self) -> None:
        self.ns = OTNS()
        self.ns.speed = OTNS.MAX_SIMULATE_SPEED

    def tearDown(self) -> None:
        self.ns.close()

    def assertFormPartitions(self, count: int):
        pars = self.ns.partitions()
        self.assertTrue(len(pars) == count and 0 not in pars, pars)