vaibruce / Basic_Circuit_Solver_in_Python

A Python program to solve simple DC circuits using Ohm’s law and Kirchhoff’s laws.
0 stars 0 forks source link

Unit tests for Ohm’s Law and KCL. #3

Closed vaibruce closed 1 month ago

vaibruce commented 1 month ago

import unittest

class TestCircuitSolver(unittest.TestCase):

# Testing Ohm's Law functions
def test_calculate_current(self):
    self.assertEqual(calculate_current(10, 5), 2)
    self.assertRaises(ValueError, calculate_current, 10, 0)

def test_calculate_voltage(self):
    self.assertEqual(calculate_voltage(2, 5), 10)

# Testing KCL
def test_solve_kcl(self):
    self.assertTrue(solve_kcl([3, -2, -1]))  # Should satisfy KCL
    self.assertFalse(solve_kcl([3, -2, -2]))  # Should violate KCL
sumanth3483 commented 1 month ago

Unit tests for Ohm’s Law and KCL.