# Path: minibot/hardware/virtual_gpio/gpio.py
# class DigitalOutput():
#     """
#     Digital output pin.
#     """
# 
#     def __init__(self, pin):
#         """
#         Constructor.
#         Args:
#             pin (int): Digital pin number.
#         """
#         self.pin = pin
#         self.state = 0
# 
#     def set_low(self):
#         """
#         Set the digital output pin to low.
#         """
#         self.state = 0
# 
#     def set_high(self):
#         """
#         Set the digital output pin to high.
#         """
#         self.state = 1
# 
# class PWM():
#     """
#     PWM used on a minibot.
#     """
#     def __init__(self, pin, frequency=1, duty_cycle=0):
#         """
#         Constructor.
#         Args:
#             pin (int): Pin that the PWM is connected to on the minibot.
#             frequency (int): Frequency of the PWM.
#             duty_cycle (int): Duty cycle of the PWM.
#         """
#         self.pin = pin
#         self.frequency = frequency
#         self.duty_cycle = duty_cycle
#         self.started = False
# 
#     def set_frequency(self, frequency):
#         """
#         Sets frequency of the PWM.
#         """
#         self.frequency = frequency
# 
#     def set_duty_cycle(self, duty_cycle):
#         """
#         Sets duty cycle of the PWM.
#         """
#         self.duty_cycle = duty_cycle
# 
#     def stop(self):
#         """
#         Stops the PWM.
#         """
#         self.started = False
# 
#     def start(self):
#         """
#         Starts the PWM.
#         """
#         self.started = True
# 
# Path: minibot/peripherals/hbridge.py
# class HBridge():
#     """
#     Minibot H-Bridge class.
#     """
#     def __init__(self, left_pin, left_pwm, right_pin, right_pwm):
#         """
#         Constructor.
#         Args:
#             left_pin (:obj:`DigitalOutput`): Left motor direction pin.
#             left_pwm (:obj:`PWM`): PWM of the servo.
#             right_pin (:obj:`DigitalOutput`): Right motor direction pin.
#             right_pwm (:obj:`PWM`): PWM of the servo.
#         """
#         self.left_pin = left_pin
#         self.left_pwm = left_pwm
#         self.right_pin = right_pin
#         self.right_pwm = right_pwm
# 
#         self.left_speed = 0
#         self.right_speed = 0
# 
#         left_pwm.set_frequency(100)
#         right_pwm.set_frequency(100)
# 
#     def get_speed(self):
#         """
#         Returns the (left speed, right speed) tuple
#         """
#         return (self.left_speed, self.right_speed)
#         
#     def set_speed(self, left, right):
#         """
#         Sets the speed of both motors.
#         Args:
#             left (float): The speed of the left motor (-100 to 100).
#             right (float): The speed of the right motor (-100 to 100).
#         """
#         self.left_speed = max(min(left, 100.0), -100.0)
#         self.right_speed = max(min(right, 100.0), -100.0)
#         # divide by hundred because PWMs have values between 1 and -1
#         # values are negated because of the wiring setup
#         left = -self.left_speed/100.0
#         right = -self.right_speed/100.0
# 
#         if left < 0:
#             self.left_pin.set_high()
#             self.left_pwm.set_duty_cycle(abs(left))
#         else:
#             self.left_pin.set_low()
#             self.left_pwm.set_duty_cycle(1-abs(left))
# 
#         if right < 0:
#             self.right_pin.set_high()
#             self.right_pwm.set_duty_cycle(abs(right))
#         else:
#             self.right_pin.set_low()
#             self.right_pwm.set_duty_cycle(1-abs(right))


import unittest
from minibot.hardware.virtual_gpio.gpio import DigitalOutput, PWM
from minibot.peripherals.hbridge import HBridge
    """
    Tests to makes sure movements work correctly
    """

    def test_initially_stopped(self):
        """ Test bot is in stopped state """
        hbridge = HBridge(DigitalOutput(10),
                          PWM(13),
                          DigitalOutput(24),
                          PWM(18))
        hbridge.set_speed(0,0)
        self.assertEqual(hbridge.left_pin.state, 0)
        self.assertEqual(hbridge.left_pwm.duty_cycle, 1)
        self.assertEqual(hbridge.right_pin.state, 0)
        self.assertEqual(hbridge.right_pwm.duty_cycle, 1)

    def test_forward(self):
        """ Tests to make sure moves forward correctly """
        hbridge = HBridge(DigitalOutput(10),
                          PWM(13),
                          DigitalOutput(24),
                          PWM(18))
        hbridge.set_speed(1, 1)
        self.assertEqual(hbridge.left_pin.state, 0)
        self.assertEqual(hbridge.left_pwm.duty_cycle, 0)
        self.assertEqual(hbridge.right_pin.state, 0)
        self.assertEqual(hbridge.right_pwm.duty_cycle, 0)

    def test_backward(self):
        """ Tests to make sure moves backward correctly """

# Path: minibot/hardware/virtual_gpio/gpio.py
# class DigitalOutput():
#     """
#     Digital output pin.
#     """
# 
#     def __init__(self, pin):
#         """
#         Constructor.
#         Args:
#             pin (int): Digital pin number.
#         """
#         self.pin = pin
#         self.state = 0
# 
#     def set_low(self):
#         """
#         Set the digital output pin to low.
#         """
#         self.state = 0
# 
#     def set_high(self):
#         """
#         Set the digital output pin to high.
#         """
#         self.state = 1
# 
# class PWM():
#     """
#     PWM used on a minibot.
#     """
#     def __init__(self, pin, frequency=1, duty_cycle=0):
#         """
#         Constructor.
#         Args:
#             pin (int): Pin that the PWM is connected to on the minibot.
#             frequency (int): Frequency of the PWM.
#             duty_cycle (int): Duty cycle of the PWM.
#         """
#         self.pin = pin
#         self.frequency = frequency
#         self.duty_cycle = duty_cycle
#         self.started = False
# 
#     def set_frequency(self, frequency):
#         """
#         Sets frequency of the PWM.
#         """
#         self.frequency = frequency
# 
#     def set_duty_cycle(self, duty_cycle):
#         """
#         Sets duty cycle of the PWM.
#         """
#         self.duty_cycle = duty_cycle
# 
#     def stop(self):
#         """
#         Stops the PWM.
#         """
#         self.started = False
# 
#     def start(self):
#         """
#         Starts the PWM.
#         """
#         self.started = True
# 
# Path: minibot/peripherals/hbridge.py
# class HBridge():
#     """
#     Minibot H-Bridge class.
#     """
#     def __init__(self, left_pin, left_pwm, right_pin, right_pwm):
#         """
#         Constructor.
#         Args:
#             left_pin (:obj:`DigitalOutput`): Left motor direction pin.
#             left_pwm (:obj:`PWM`): PWM of the servo.
#             right_pin (:obj:`DigitalOutput`): Right motor direction pin.
#             right_pwm (:obj:`PWM`): PWM of the servo.
#         """
#         self.left_pin = left_pin
#         self.left_pwm = left_pwm
#         self.right_pin = right_pin
#         self.right_pwm = right_pwm
# 
#         self.left_speed = 0
#         self.right_speed = 0
# 
#         left_pwm.set_frequency(100)
#         right_pwm.set_frequency(100)
# 
#     def get_speed(self):
#         """
#         Returns the (left speed, right speed) tuple
#         """
#         return (self.left_speed, self.right_speed)
#         
#     def set_speed(self, left, right):
#         """
#         Sets the speed of both motors.
#         Args:
#             left (float): The speed of the left motor (-100 to 100).
#             right (float): The speed of the right motor (-100 to 100).
#         """
#         self.left_speed = max(min(left, 100.0), -100.0)
#         self.right_speed = max(min(right, 100.0), -100.0)
#         # divide by hundred because PWMs have values between 1 and -1
#         # values are negated because of the wiring setup
#         left = -self.left_speed/100.0
#         right = -self.right_speed/100.0
# 
#         if left < 0:
#             self.left_pin.set_high()
#             self.left_pwm.set_duty_cycle(abs(left))
#         else:
#             self.left_pin.set_low()
#             self.left_pwm.set_duty_cycle(1-abs(left))
# 
#         if right < 0:
#             self.right_pin.set_high()
#             self.right_pwm.set_duty_cycle(abs(right))
#         else:
#             self.right_pin.set_low()
#             self.right_pwm.set_duty_cycle(1-abs(right))


# Path: minibot/peripherals/test_hbridge.py
import unittest
from minibot.hardware.virtual_gpio.gpio import DigitalOutput, PWM
from minibot.peripherals.hbridge import HBridge

    """
    Tests to makes sure movements work correctly
    """

    def test_initially_stopped(self):
        """ Test bot is in stopped state """
        hbridge = HBridge(DigitalOutput(10),
                          PWM(13),
                          DigitalOutput(24),
                          PWM(18))
        hbridge.set_speed(0,0)
        self.assertEqual(hbridge.left_pin.state, 0)
        self.assertEqual(hbridge.left_pwm.duty_cycle, 1)
        self.assertEqual(hbridge.right_pin.state, 0)
        self.assertEqual(hbridge.right_pwm.duty_cycle, 1)

    def test_forward(self):
        """ Tests to make sure moves forward correctly """
        hbridge = HBridge(DigitalOutput(10),
                          PWM(13),
                          DigitalOutput(24),
                          PWM(18))
        hbridge.set_speed(1, 1)
        self.assertEqual(hbridge.left_pin.state, 0)
        self.assertEqual(hbridge.left_pwm.duty_cycle, 0)
        self.assertEqual(hbridge.right_pin.state, 0)
        self.assertEqual(hbridge.right_pwm.duty_cycle, 0)

    def test_backward(self):
        """ Tests to make sure moves backward correctly """

        hbridge = HBridge(DigitalOutput(10),