Skip to content
Snippets Groups Projects
Commit bfb2ca9a authored by Hatice Yildirim's avatar Hatice Yildirim
Browse files

Merge branch 'feature/PikemaatLasse' into 'develop'

PikemaatLasse

See merge request !4
parents 54ec5f55 1596c413
No related branches found
No related tags found
2 merge requests!8Develop2,!4PikemaatLasse
Showing
with 463 additions and 0 deletions
#Bei Eingabe von Zahlen, die in der Liste definiert sind, sollen römische Zhalen zurückgegeben werden.
#Bei Eingabe von Zahlen, die nicht in der Liste definiert ist, soll ein "" ausgeben werden.
import unittest
from abc import ABC, abstractmethod
class IRomanNumber(ABC):
@abstractmethod
def convert(self, n:int) -> str:
pass
class RomanNumber(IRomanNumber):
def convert(self, n: int) -> str:
roman_numerals = {
1: "I", 2: "II", 3: "III",
4: "IV", 5: "V", 9: "IX",
21: "XXI", 50: "L", 100: "C",
500: "D", 1000: "M"
}
return roman_numerals.get(n, "")
class TestRomanConverter(unittest.TestCase):
def setUp(self):
self.converter = RomanNumber()
def test_single_value(self):
self.assertEqual(self.converter.convert(1), "I")
self.assertEqual(self.converter.convert(2), "II")
self.assertEqual(self.converter.convert(3), "III")
self.assertEqual(self.converter.convert(4), "IV")
self.assertEqual(self.converter.convert(5), "V")
self.assertEqual(self.converter.convert(9), "IX")
self.assertEqual(self.converter.convert(21), "XXI")
self.assertEqual(self.converter.convert(50), "L")
self.assertEqual(self.converter.convert(100), "C")
self.assertEqual(self.converter.convert(500), "D")
self.assertEqual(self.converter.convert(1000), "M")
def test_inivalid_numbers(self):
self.assertEqual(self.converter.convert(6), "")
self.assertEqual(self.converter.convert(99), "")
self.assertEqual(self.converter.convert(-1), "")
if __name__ == "__main__":
unittest.main()
#Umsetzungen von PikkemaatLasse auf meine Testfälle
import unittest
from src.romannumerals import RomanNumerals as RomanNumber
from src.interfaces import IRomanNumerals
class TestRomanConverter(unittest.TestCase):
def setUp(self):
self.converter = RomanNumber()
def test_implements_interface(self):
self.assertIsInstance(self.converter, IRomanNumerals)
def test_single_value(self):
self.assertEqual(self.converter.convert(1), "I")
self.assertEqual(self.converter.convert(2), "II")
self.assertEqual(self.converter.convert(3), "III")
self.assertEqual(self.converter.convert(4), "IV")
self.assertEqual(self.converter.convert(5), "V")
self.assertEqual(self.converter.convert(9), "IX")
self.assertEqual(self.converter.convert(21), "XXI")
self.assertEqual(self.converter.convert(50), "L")
self.assertEqual(self.converter.convert(100), "C")
self.assertEqual(self.converter.convert(500), "D")
self.assertEqual(self.converter.convert(1000), "M")
def test_inivalid_numbers(self):
self.assertEqual(self.converter.convert(6), "")
self.assertEqual(self.converter.convert(99), "")
self.assertEqual(self.converter.convert(-1), "")
if __name__ == "__main__":
unittest.main()
# PraxisprojektTechnologiebasierteInnovation
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.reutlingen-university.de/Lasse.Pikkemaat/praxisprojekttechnologiebasierteinnovation.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.reutlingen-university.de/Lasse.Pikkemaat/praxisprojekttechnologiebasierteinnovation/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
print("Hello WORLD")
print("test")
\ No newline at end of file
File added
File added
File added
File added
File added
File added
#Test1: Addition 2 positiver Zaheln (2+5) erwartetes Ergebnis 8
#Test2: Addition negativer und positiver Zahl (-1+1) erwartetes Ergebnis 0
#Test3: Addition (0+0), erwartetes Ergebnis 0
#Test4: Addition von 2 Dezimalzahlen (2,5+3,5), erwartetes Ergebnis 6
from abc import ABC, abstractmethod
class ICalculator(ABC):
@abstractmethod
def add(self, a: float, b: float) -> float:
pass
class Calculator(ICalculator):
def add(self, a: float, b: float) -> float:
return a + b
class TestCalculator:
def __init__(self, calculator: ICalculator):
self.calculator = calculator
def test_add(self):
assert self.calculator.add(2,3) == 5, "Fehler falls nicht 5"
assert self.calculator.add(-1,1) == 0, "Fegler falls nich 0"
assert self.calculator.add(0,0) == 0, "Fehler falls nicht 0"
assert self.calculator.add(2.5,3.5) == 6, "Fehler falls nicht 5"
print("Test erfolgreich")
if __name__ == "__main__":
calc = Calculator()
tester = TestCalculator(calc)
tester.test_add()
#Bei Eingabe des Strings "Decker" liefert die Funktion 3
#Bei Eingabe eines leeren Stings soll 0 augegeben werden
#Bei Eingabe des Strings "Hallo" ohne E und D soll 0 ausgegeben werden
#Bei Eingabe von dem String "Der Esel" soll Groß-Kleinschreibung (Caseinsensitive) gezählt werden. das Ergebnis ist 4
#Bei Eingabe des Buchstaben D oder E soll 1 ausgegeben werden
from abc import ABC,abstractmethod
import unittest
class ICounter (ABC):
@abstractmethod
def count_ED(self,s):
pass
class Counter (ICounter):
def count_ED(self, s):
s=s.upper()
return s.count("D")+s.count("E")
class TestCounter (unittest.TestCase):
def setUp(self):
self.c=Counter()
def test_count_ED_regular (self):
res=self.c.count_ED ("Decker")
self.assertEqual(res,3)
def test_count_ED_empty (self):
res=self.c.count_ED ("")
self.assertEqual(res,0)
def test_count_ED_wo (self):
'''Testet einen String ohne E und D'''
res=self.c.count_ED ("Hallo")
self.assertEqual(res,0)
def test_count_ED_case_insensitive (self):
'''Testet verschiedene Groß- und Kleinschreibungen'''
res=self.c.count_ED ("Der Esel")
self.assertEqual(res,4)
def test_count_ED_single_letetr (self):
'''Testet Eingaben mit nur einem Buchstaben'''
res=self.c.count_ED ('D')
self.assertEqual(res,1)
res=self.c.count_ED ('E')
self.assertEqual (res,1)
res=self.c.count_ED ('d')
self.assertEqual(res,1)
res=self.c.count_ED ('e')
self.assertEqual (res,1)
if __name__=="__main__":
unittest.main()
\ No newline at end of file
from abc import ABC, abstractmethod
class IRomanNumerals(ABC):
@abstractmethod
def to_roman(self, num):
pass
\ No newline at end of file
from src.interfaces import IRomanNumerals
class RomanNumerals(IRomanNumerals):
def to_roman(self, num):
if not isinstance(num, int):
raise ValueError("Eingabe muss eine ganze Zahl sein")
if num <= 0 or num >= 4000:
raise ValueError("Zahl muss zwischen 1 und 3999 liegen")
val = [
(1000, "M"), (900, "CM"), (500, "D"), (400, "CD"),
(100, "C"), (90, "XC"), (50, "L"), (40, "XL"),
(10, "X"), (9, "IX"), (5, "V"), (4, "IV"),
(1, "I")
]
result = ""
for (value, numeral) in val:
while num >= value:
result += numeral
num -= value
return result
\ No newline at end of file
# Basisfälle
# Bei Eingabe der Zahl 1, erhalte ich das Ergebnis I
# Bei Eingabe der Zahl 5, erhalte ich das Ergebnis V
# Bei Eingabe der Zahl 10, erhalte ich das Ergebnis X
# Bei Eingabe der Zahl 50, erhalte ich das Ergebnis L
# Bei Eingabe der Zahl 100, erhalte ich das Ergebnis C
# Bei Eingabe der Zahl 500, erhalte ich das Ergebnis D
# Bei Eingabe der Zahl 1000, erhalte ich das Ergebnis M
# Substraktionsregel
# Bei Eingabe der Zahl 4, erhalte ich das Ergebnis IV
# Bei Eingabe der Zahl 9, erhalte ich das Ergebnis IX
# Bei Eingabe der Zahl 40, erhalte ich das Ergebnis XL
# Bei Eingabe der Zahl 90, erhalte ich das Ergebnis XC
# Bei Eingabe der Zahl 400, erhalte ich das Ergebnis CD
# Bei Eingabe der Zahl 900, erhalte ich das Ergebnis CM
# Additionsregel
# Bei Eingabe der Zahl 2 erhalte ich das Ergebnis "II"
# Bei Eingabe der Zahl 3 erhalte ich das Ergebnis "III"
# Bei Eingabe der Zahl 6 erhalte ich das Ergebnis "VI"
# Bei Eingabe der Zahl 8 erhalte ich das Ergebnis "VIII"
# Bei Eingabe der Zahl 30 erhalte ich das Ergebnis "XXX"
# Bei Eingabe der Zahl 80 erhalte ich das Ergebnis "LXXX"
# Kombination aus Addition und Subtraktion
# Bei Eingabe der Zahl 14 erhalte ich das Ergebnis "XIV"
# Bei Eingabe der Zahl 19 erhalte ich das Ergebnis "XIX"
# Bei Eingabe der Zahl 29 erhalte ich das Ergebnis "XXIX"
# Bei Eingabe der Zahl 44 erhalte ich das Ergebnis "XLIV"
# Bei Eingabe der Zahl 99 erhalte ich das Ergebnis "XCIX"
# Bei Eingabe der Zahl 444 erhalte ich das Ergebnis "CDXLIV"
# Bei Eingabe der Zahl 999 erhalte ich das Ergebnis "CMXCIX"
# Größere Zahlen
# Bei Eingabe der Zahl 1001 erhalte ich das Ergebnis "MI"
# Bei Eingabe der Zahl 1987 erhalte ich das Ergebnis "MCMLXXXVII"
# Bei Eingabe der Zahl 2023 erhalte ich das Ergebnis "MMXXIII"
# Bei Eingabe der Zahl 3999 erhalte ich das Ergebnis "MMMCMXCIX"
# Fehlerfälle
# Bei Eingabe der Zahl 0 erhalte ich eine Fehlermeldung
# Bei Eingabe der Zahl -1 erhalte ich eine Fehlermeldung
# Bei Eingabe der Zahl 4000 erhalte ich eine Fehlermeldung
# Bei Eingabe der Zeichenfolge "ABC" erhalte ich eine Fehlermeldung
# Bei Eingabe von None erhalte ich eine Fehlermeldung
# Bei Eingabe der Zahl 3.14 erhalte ich eine Fehlermeldung
import unittest
from src.romannumerals import RomanNumerals
class TestRomanNumerals(unittest.TestCase):
def setUp(self):
self.converter = RomanNumerals()
def test_to_roman_basic(self):
self.assertEqual(self.converter.to_roman(1), "I")
self.assertEqual(self.converter.to_roman(5), "V")
self.assertEqual(self.converter.to_roman(10), "X")
self.assertEqual(self.converter.to_roman(50), "L")
self.assertEqual(self.converter.to_roman(100), "C")
self.assertEqual(self.converter.to_roman(500), "D")
self.assertEqual(self.converter.to_roman(1000), "M")
def test_to_roman_subtraction(self):
self.assertEqual(self.converter.to_roman(4), "IV")
self.assertEqual(self.converter.to_roman(9), "IX")
self.assertEqual(self.converter.to_roman(40), "XL")
self.assertEqual(self.converter.to_roman(90), "XC")
self.assertEqual(self.converter.to_roman(400), "CD")
self.assertEqual(self.converter.to_roman(900), "CM")
def test_to_roman_addition(self):
self.assertEqual(self.converter.to_roman(2), "II")
self.assertEqual(self.converter.to_roman(3), "III")
self.assertEqual(self.converter.to_roman(6), "VI")
self.assertEqual(self.converter.to_roman(8), "VIII")
self.assertEqual(self.converter.to_roman(30), "XXX")
self.assertEqual(self.converter.to_roman(80), "LXXX")
def test_to_roman_mixed(self):
self.assertEqual(self.converter.to_roman(14), "XIV")
self.assertEqual(self.converter.to_roman(19), "XIX")
self.assertEqual(self.converter.to_roman(29), "XXIX")
self.assertEqual(self.converter.to_roman(44), "XLIV")
self.assertEqual(self.converter.to_roman(99), "XCIX")
self.assertEqual(self.converter.to_roman(444), "CDXLIV")
self.assertEqual(self.converter.to_roman(999), "CMXCIX")
def test_to_roman_large_numbers(self):
self.assertEqual(self.converter.to_roman(1001), "MI")
self.assertEqual(self.converter.to_roman(1987), "MCMLXXXVII")
self.assertEqual(self.converter.to_roman(2023), "MMXXIII")
self.assertEqual(self.converter.to_roman(3999), "MMMCMXCIX")
def test_to_roman_invalid(self):
with self.assertRaises(ValueError):
self.converter.to_roman(0)
with self.assertRaises(ValueError):
self.converter.to_roman(-1)
with self.assertRaises(ValueError):
self.converter.to_roman(4000)
with self.assertRaises(ValueError):
self.converter.to_roman("ABC")
with self.assertRaises(ValueError):
self.converter.to_roman(None)
with self.assertRaises(ValueError):
self.converter.to_roman(3.14)
if __name__ == "__main__":
unittest.main()
\ No newline at end of file
import unittest
from converter import RomanNumber
from converter import IRomanNumber
class TestRomanNumerals(unittest.TestCase):
def setUp(self):
self.converter = RomanNumber()
def test_implements_interface(self):
self.assertIsInstance(self.converter, IRomanNumber)
def test_to_roman_basic(self):
self.assertEqual(self.converter.to_roman(1), "I")
self.assertEqual(self.converter.to_roman(5), "V")
self.assertEqual(self.converter.to_roman(10), "X")
self.assertEqual(self.converter.to_roman(50), "L")
self.assertEqual(self.converter.to_roman(100), "C")
self.assertEqual(self.converter.to_roman(500), "D")
self.assertEqual(self.converter.to_roman(1000), "M")
def test_to_roman_subtraction(self):
self.assertEqual(self.converter.to_roman(4), "IV")
self.assertEqual(self.converter.to_roman(9), "IX")
self.assertEqual(self.converter.to_roman(40), "XL")
self.assertEqual(self.converter.to_roman(90), "XC")
self.assertEqual(self.converter.to_roman(400), "CD")
self.assertEqual(self.converter.to_roman(900), "CM")
def test_to_roman_addition(self):
self.assertEqual(self.converter.to_roman(2), "II")
self.assertEqual(self.converter.to_roman(3), "III")
self.assertEqual(self.converter.to_roman(6), "VI")
self.assertEqual(self.converter.to_roman(8), "VIII")
self.assertEqual(self.converter.to_roman(30), "XXX")
self.assertEqual(self.converter.to_roman(80), "LXXX")
def test_to_roman_mixed(self):
self.assertEqual(self.converter.to_roman(14), "XIV")
self.assertEqual(self.converter.to_roman(19), "XIX")
self.assertEqual(self.converter.to_roman(29), "XXIX")
self.assertEqual(self.converter.to_roman(44), "XLIV")
self.assertEqual(self.converter.to_roman(99), "XCIX")
self.assertEqual(self.converter.to_roman(444), "CDXLIV")
self.assertEqual(self.converter.to_roman(999), "CMXCIX")
def test_to_roman_large_numbers(self):
self.assertEqual(self.converter.to_roman(1001), "MI")
self.assertEqual(self.converter.to_roman(1987), "MCMLXXXVII")
self.assertEqual(self.converter.to_roman(2023), "MMXXIII")
self.assertEqual(self.converter.to_roman(3999), "MMMCMXCIX")
def test_to_roman_invalid(self):
with self.assertRaises(ValueError):
self.converter.to_roman(0)
with self.assertRaises(ValueError):
self.converter.to_roman(-1)
with self.assertRaises(ValueError):
self.converter.to_roman(4000)
with self.assertRaises(ValueError):
self.converter.to_roman("ABC")
with self.assertRaises(ValueError):
self.converter.to_roman(None)
with self.assertRaises(ValueError):
self.converter.to_roman(3.14)
if __name__ == "__main__":
unittest.main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment