LogarithmPlotter/runtime-pyside6/tests/plugins/natural/interfaces/basic.py

84 lines
2.5 KiB
Python
Raw Normal View History

2024-10-16 20:18:53 +00:00
"""
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
* Copyright (C) 2021-2024 Ad5001
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
2024-10-17 00:08:24 +00:00
from .assertion import Assertion
from .base import BaseAssertionInterface
from .int import NumberInterface
from .utils import repr_
2024-10-16 20:18:53 +00:00
class FixedIteratorInterface(BaseAssertionInterface):
@property
2024-10-17 00:08:24 +00:00
def length(self) -> NumberInterface:
return NumberInterface(len(self._value), self)
2024-10-16 20:18:53 +00:00
def elements(self, *elements) -> Assertion:
2024-10-17 00:08:24 +00:00
tests = [repr_(elem) for elem in elements if elem not in self._value]
2024-10-16 20:18:53 +00:00
return Assertion(
len(tests) == 0,
2024-10-17 00:08:24 +00:00
f"This value ({repr_(self._value)}) does not have elements {', '.join(tests)}.",
self._not
2024-10-16 20:18:53 +00:00
)
def element(self, element) -> Assertion:
return Assertion(
element in self._value,
2024-10-17 00:08:24 +00:00
f"This value ({repr_(self._value)}) does not have element {repr_(element)}.",
self._not
2024-10-16 20:18:53 +00:00
)
def contains(self, *elements) -> Assertion:
2024-10-17 00:08:24 +00:00
"""
Check if the element(s) are contained in the iterator.
"""
if len(elements) == 1:
return self.element(elements[0])
else:
return self.elements(*elements)
def contain(self, *elements):
"""
Check if the element(s) are contained in the iterator.
"""
return self.contains(*elements)
2024-10-16 20:18:53 +00:00
class BoolInterface(BaseAssertionInterface):
@property
2024-10-17 00:08:24 +00:00
def true(self):
2024-10-16 20:18:53 +00:00
return Assertion(
self._value == True,
2024-10-17 00:08:24 +00:00
f"The value ({repr_(self._value)}) is not True.",
self._not
2024-10-16 20:18:53 +00:00
)
@property
2024-10-17 00:08:24 +00:00
def false(self):
2024-10-16 20:18:53 +00:00
return Assertion(
self._value == False,
2024-10-17 00:08:24 +00:00
f"The value ({repr_(self._value)}) is not False.",
self._not
2024-10-16 20:18:53 +00:00
)
2024-10-17 00:08:24 +00:00
class StringInterface(FixedIteratorInterface):
pass
class ListInterface(FixedIteratorInterface):
pass