Skip to content

Commit

Permalink
0.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
piz2a authored Jan 29, 2019
1 parent ba5686c commit b02b6c9
Show file tree
Hide file tree
Showing 26 changed files with 113 additions and 47 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018 jiho2007
Copyright (c) 2019 jiho2007

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This Library implements 'frac' class.
You can add, subtract, multiplicate, divide Fractions.

The Lastest Version Of mFrac is 0.2.1
The Lastest Version Of mFrac is 0.3.1

**How to install:** *pip install -i https://test.pypi.org/simple/ mfrac*
**How to upgrade:** *pip install -i https://test.pypi.org/simple/ mfrac --upgrade*
Expand Down
2 changes: 1 addition & 1 deletion build/lib/mfrac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#__init__.py
#Script By jiho2007

__all__ = ['frac']
__all__ = ['frac', 'error']
42 changes: 32 additions & 10 deletions build/lib/mfrac/frac.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
#frac.py
#Script By jiho2007

from .error import FractionError
try:
from .error import FractionError
except:
FractionError = TypeError

class frac:
def __init__(self, n, m=1):
if type(n) == str or type(m) == str:
try:
float(n)+float(m) #check
except:
raise FractionError('Invalid Argument Type')
if type(n) == frac:
self.n = n.n
self.n = n.m
self.n = n #분자
self.m = m #분모
if type(n) == str:
self.n = float(n)
if type(m) == str:
self.m = float(m)
if type(n) != int and n % 1 == 0: #int화
self.n = int(n)
if type(m) != int and m % 1 == 0:
self.m = int(m)

def __repr__(self): #str로 변환
return 'frac(n={}, m={})'.format(self.n, self.m)
return 'frac({}, {})'.format(self.n, self.m)

def __str__(self):
return '{}/{}'.format(self.n, self.m)
Expand All @@ -40,7 +52,7 @@ def __sub__(self, f): #뺄셈
else:
return 0
return frac(rn, self.m*f.m).reduc()
return self.__sub__(frac(1))
return self.__sub__(frac(f))

def __mul__(self, f): #곱셈
if type(f) == frac:
Expand Down Expand Up @@ -73,7 +85,7 @@ def __eq__(self, f): #같은지 비교
a = self.common(f)
b = f.common(self)
return a.n == b.n and a.m == b.m
return self.__eq__(frac(1))
return self.__eq__(frac(f))

def __ne__(self, f): #같지 않은지 비교
return not self.__eq__(f)
Expand All @@ -83,32 +95,42 @@ def __lt__(self, f): #작은지 비교
a = self.common(f)
b = f.common(self)
return a.n < b.n and a.m == b.m
return self.__lt__(frac(1))
return self.__lt__(frac(f))

def __le__(self, f): #작거나 같은지 비교
if type(f) == frac:
a = self.common(f)
b = f.common(self)
return a.n <= b.n and a.m == b.m
return self.__le__(frac(1))
return self.__le__(frac(f))

def __gt__(self, f): #큰지 비교
if type(f) == frac:
a = self.common(f)
b = f.common(self)
return a.n > b.n and a.m == b.m
return self.__lt__(frac(1))
return self.__lt__(frac(f))

def __ge__(self, f): #크거나 같은지 비교
if type(f) == frac:
a = self.common(f)
b = f.common(self)
return a.n >= b.n and a.m == b.m
return self.__le__(frac(1))
return self.__le__(frac(f))

def toFloat(self): #소수로 반환
def __float__(self): #소수
return float(self.n) / float(self.m)

def __int__(self): #소수버림 값
return int(self.float())

def __mod__(self, f): #n과 m 설정 메서드
if type(f) == frac:
self.__init__(f)
a = list(f) #check that f is iterable
self.n, self.m = f
return self

def reduc(self): #약분
if self.m<self.n:
c=self.m
Expand Down
20 changes: 16 additions & 4 deletions build/lib/mfrac/test.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#test.py
#Script By jiho2007

"""
NOTE: ONLY FOR TESTING PACKAGE FOR DEVELOPERS.
DONT IMPORT IT.
"""

import unittest

from frac import frac
from error import FractionError

class Test(unittest.TestCase):
def setUp(self):
self.half = frac(1, 2)
self.div3 = frac(1, 3)
self.fds = frac(4, 8)
self.opf = frac(1.5, 3)

self.x = frac(3,2)

def test_reduc(self):
self.assertEqual(self.fds.reduc(), self.half)
Expand All @@ -20,13 +26,16 @@ def test_common(self):
self.assertEqual(self.half.common(self.div3).n, 3)

def test_tofloat(self):
self.assertEqual(self.half.toFloat(), 0.5)
self.assertEqual(float(self.half), 0.5)

def test_add(self):
self.assertEqual(self.half + self.div3, frac(5, 6))

def test_sub(self):
self.assertEqual(1 - self.div3, frac(2, 3))

def test_sub2(self):
self.assertEqual(frac(11,2) - 5, frac(1,2))

def test_mul(self):
self.assertEqual(self.half * self.div3, frac(1, 6))
Expand All @@ -52,17 +61,20 @@ def test_gt(self):
def test_ge(self):
self.assertEqual(self.half >= self.div3, True)

def test_mod(self):
self.assertEqual(self.x%(4,3), frac(4,3))

def test_reversed(self):
self.assertEqual(reversed(self.half), frac(2, 1))

def test_reversed_float(self):
self.assertEqual(reversed(self.half).toFloat(), 2)
self.assertEqual(float(reversed(self.half)), 2)

def test_error_init(self):
try:
b = False
x = frac('hello', 'world')
except FractionError:
except:
b = True
self.assertEqual(b, True)

Expand Down
Binary file added dist/mfrac-0.3.1-py3-none-any.whl
Binary file not shown.
Binary file added dist/mfrac-0.3.1.tar.gz
Binary file not shown.
8 changes: 8 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ True
True
>>> frac(3, 6) >= frac(6, 9) #Greater than and Equals
False
```

**Set Numerator and Denominator**
```python
>>> x = frac(1,2)
>>> x % (3,4)
>>> print(x)
3/4
```
7 changes: 2 additions & 5 deletions mfrac.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: mfrac
Version: 0.2.1
Version: 0.3.1
Summary: A Small Fraction Class Package
Home-page: https://github.com/jiho2007/mFrac
Author: jiho2007
Expand All @@ -13,7 +13,7 @@ Description: # mFrac
This Library implements 'frac' class.
You can add, subtract, multiplicate, divide Fractions.

The Lastest Version Of mFrac is 0.2
The Lastest Version Of mFrac is 0.3.1

**How to install:** *pip install -i https://test.pypi.org/simple/ mfrac*
**How to upgrade:** *pip install -i https://test.pypi.org/simple/ mfrac --upgrade*
Expand All @@ -23,7 +23,4 @@ Description: # mFrac


Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
2 changes: 1 addition & 1 deletion mfrac/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#__init__.py
#Script By jiho2007

__all__ = ['frac']
__all__ = ['frac', 'error']
Binary file modified mfrac/__pycache__/frac.cpython-36.pyc
Binary file not shown.
42 changes: 32 additions & 10 deletions mfrac/frac.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
#frac.py
#Script By jiho2007

from .error import FractionError
try:
from .error import FractionError
except:
FractionError = TypeError

class frac:
def __init__(self, n, m=1):
if type(n) == str or type(m) == str:
try:
float(n)+float(m) #check
except:
raise FractionError('Invalid Argument Type')
if type(n) == frac:
self.n = n.n
self.n = n.m
self.n = n #분자
self.m = m #분모
if type(n) == str:
self.n = float(n)
if type(m) == str:
self.m = float(m)
if type(n) != int and n % 1 == 0: #int화
self.n = int(n)
if type(m) != int and m % 1 == 0:
self.m = int(m)

def __repr__(self): #str로 변환
return 'frac(n={}, m={})'.format(self.n, self.m)
return 'frac({}, {})'.format(self.n, self.m)

def __str__(self):
return '{}/{}'.format(self.n, self.m)
Expand All @@ -40,7 +52,7 @@ def __sub__(self, f): #뺄셈
else:
return 0
return frac(rn, self.m*f.m).reduc()
return self.__sub__(frac(1))
return self.__sub__(frac(f))

def __mul__(self, f): #곱셈
if type(f) == frac:
Expand Down Expand Up @@ -73,7 +85,7 @@ def __eq__(self, f): #같은지 비교
a = self.common(f)
b = f.common(self)
return a.n == b.n and a.m == b.m
return self.__eq__(frac(1))
return self.__eq__(frac(f))

def __ne__(self, f): #같지 않은지 비교
return not self.__eq__(f)
Expand All @@ -83,32 +95,42 @@ def __lt__(self, f): #작은지 비교
a = self.common(f)
b = f.common(self)
return a.n < b.n and a.m == b.m
return self.__lt__(frac(1))
return self.__lt__(frac(f))

def __le__(self, f): #작거나 같은지 비교
if type(f) == frac:
a = self.common(f)
b = f.common(self)
return a.n <= b.n and a.m == b.m
return self.__le__(frac(1))
return self.__le__(frac(f))

def __gt__(self, f): #큰지 비교
if type(f) == frac:
a = self.common(f)
b = f.common(self)
return a.n > b.n and a.m == b.m
return self.__lt__(frac(1))
return self.__lt__(frac(f))

def __ge__(self, f): #크거나 같은지 비교
if type(f) == frac:
a = self.common(f)
b = f.common(self)
return a.n >= b.n and a.m == b.m
return self.__le__(frac(1))
return self.__le__(frac(f))

def toFloat(self): #소수로 반환
def __float__(self): #소수
return float(self.n) / float(self.m)

def __int__(self): #소수버림 값
return int(self.float())

def __mod__(self, f): #n과 m 설정 메서드
if type(f) == frac:
self.__init__(f)
a = list(f) #check that f is iterable
self.n, self.m = f
return self

def reduc(self): #약분
if self.m<self.n:
c=self.m
Expand Down
Loading

0 comments on commit b02b6c9

Please sign in to comment.