Skip to content
Snippets Groups Projects
Commit fd54d87a authored by Nils Schäfer's avatar Nils Schäfer
Browse files

Init

parents
No related branches found
No related tags found
No related merge requests found
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
{
// Verwendet IntelliSense zum Ermitteln möglicher Attribute.
// Zeigen Sie auf vorhandene Attribute, um die zugehörigen Beschreibungen anzuzeigen.
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python-Debugger: Aktuelle Datei",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
\ No newline at end of file
{
"python.testing.unittestArgs": [
"-v",
"-s",
".",
"-p",
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
\ No newline at end of file
class Calculator:
@staticmethod
def multiplication(a, b):
return a * b
# Aufgabe 1a: Determinante einer 3x3-Matrix berechnen
@staticmethod
def matrix_det_3x3(mat):
# Überprüfen, ob die Matrix eine 3x3-Matrix ist
if len(mat) != 3 or len(mat[0]) != 3:
raise ValueError("Die übergebene Matrix ist keine 3x3-Matrix.")
# Berechnung der Determinante mittels der Regel von Sarrus
det = 0
det += mat[0][0] * (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1])
det -= mat[0][1] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0])
det += mat[0][2] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0])
return det
# Aufgabe 1b: Matrizenmultiplikation
@staticmethod
def matrix_multiplication(matA, matB):
# Prüfen, ob das Matrixprodukt definiert ist (Anzahl der Spalten von matA == Anzahl der Zeilen von matB)
if len(matA[0]) != len(matB):
raise ValueError("Das Matrixprodukt ist nicht definiert.")
rowsA = len(matA)
colsA = len(matA[0])
colsB = len(matB[0])
# Ergebnis-Matrix initialisieren
result = [[0 for _ in range(colsB)] for _ in range(rowsA)]
# Berechnung des Matrixprodukts
for i in range(rowsA):
for j in range(colsB):
for k in range(colsA):
result[i][j] += matA[i][k] * matB[k][j]
return result
\ No newline at end of file
README 0 → 100644
# Hausuebung1
## Descritpion
+ Hausübung 1 für GDI:
- Matrixmulitplikation
## Structure
- hue1CS: C#-Console Code
- **hue1PY: Python Code**
## Installation and Usage
To run the code, you must have Visual Studio Code and Python 3.13 installed.
Activate Profile: GDI Python
## Authors and acknowledgment
NilsSchaefer
## License
No License, free to use for educational purpose.
## Project status
Finished
import unittest
import sys
import os
# Den übergeordneten Verzeichnispfad hinzufügen
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from Calculator import Calculator
class TestCalculator(unittest.TestCase):
def test_multiplication(self):
a = 2
b = 3
result = Calculator.multiplication(a, b)
self.assertEqual(result, 6)
def test_matrix_det_3x3(self):
matA = [[3, 2, 1], [6, 4, 5], [3, 9, 7]]
result = Calculator.matrix_det_3x3(matA)
self.assertEqual(result, -63)
def test_matrix_det_3x3_error(self):
matA = [[3, 2], [6, 4], [3, 9]]
with self.assertRaises(ValueError):
Calculator.matrix_det_3x3(matA)
def test_matrix_product_error(self):
matA = [[3, 2], [6, 4], [3, 9]]
matB = [[3, 2, 1], [6, 4, 5], [3, 9, 7]]
with self.assertRaises(ValueError):
Calculator.matrix_multiplication(matA, matB)
def test_matrix_product(self):
matA = [[3, 2, 1], [6, 4, 5], [3, 9, 7]]
matB = [[3, 2, 1], [6, 4, 5], [3, 9, 7]]
matTrue = [[24, 23, 20], [57, 73, 61], [84, 105, 97]]
result = Calculator.matrix_multiplication(matA, matB)
self.assertEqual(result, matTrue)
if __name__ == '__main__':
unittest.main()
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