Skip to content

Commit a30ffd6

Browse files
author
Jochen Bauer
committed
implemented first unittests and basic structure
1 parent d99b5ea commit a30ffd6

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Monkeybyte
2+
3+
This is MonkeyByte, a binary calculator. More to come.

binarycalculator.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
FILE: Binarycalculator.py
4+
DESCRIPTION: A module that provides all necessary stuff to handle binary
5+
and hex conversions and interpretions for a binary calculator.
6+
AUTHOR: Jochen Bauer
7+
CREATION DATE: 20170414
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
LICENSE: GPL version 3
10+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11+
This file is part of MonkeyByte.
12+
13+
MonkeyByte is free software: you can redistribute it and/or modify
14+
it under the terms of the GNU General Public License as published by
15+
the Free Software Foundation, either version 3 of the License, or
16+
(at your option) any later version.
17+
18+
MonkeyByte is distributed in the hope that it will be useful,
19+
but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
GNU General Public License for more details.
22+
23+
You should have received a copy of the GNU General Public License
24+
along with MonkeyByte. If not, see <http://www.gnu.org/licenses/>.
25+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
26+
"""
27+
28+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
# ~~~~~~~~~~~~~~~~~~~~~ IMPORTS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31+
32+
import bitstring
33+
34+
class BinCalc:
35+
""" the main calculator class """
36+
def __init__(self, currentValue=0):
37+
self._currentValue = currentValue
38+
self._currentBitarray = bitstring.BitArray(Bits().int = _currentValue)
39+
40+
def hex(self):
41+
""" Returns a hexadecimal string representation of the current value """
42+
return str(hex(self._currentValue))[2:]
43+
44+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
45+
# ~~~~~~~~~~~~~~~~~~~~~ PROPERTIES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47+
48+
@property
49+
def currentValue(self):
50+
""" currentValue getter """
51+
return self._currentValue
52+
53+
@currentValue.setter
54+
def currentValue(self, value):
55+
""" currentValue setter """
56+
self._currentValue = value
57+
self.
58+

test_monkeybyte.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
""" test module to test MonkeyByte using pytest """
2+
import binarycalculator
3+
4+
BC = binarycalculator.BinCalc()
5+
6+
TESTVAL = 1337
7+
TESTVAL_HEXSTR = "539"
8+
TESTVAL_BITSTR = "010100111001"
9+
10+
def test_value_assignment():
11+
""" test if variable has been assigned """
12+
BC.currentValue = TESTVAL
13+
assert BC.currentValue == TESTVAL
14+
15+
def test_hex():
16+
""" get current value as hex """
17+
BC.currentValue = TESTVAL
18+
assert BC.hex() == TESTVAL_HEXSTR

0 commit comments

Comments
 (0)