import io
import unittest
from unittest.mock import patch
from kattis import k_lipschitzconstant

###############################################################################

class SampleInput(unittest.TestCase):
    '''Problem statement sample inputs and outputs'''

    def test_sample_input_1(self):
        '''Run and assert problem statement sample 1 input and output.'''
        inputs = []
        inputs.append('3')
        inputs.append('1 1')
        inputs.append('2 2')
        inputs.append('3 4')
        inputs = '\n'.join(inputs) + '\n'

        outputs = '2.000000000\n'

        with patch('sys.stdin', io.StringIO(inputs)) as stdin,\
             patch('sys.stdout', new_callable=io.StringIO) as stdout:
            k_lipschitzconstant.main()
            self.assertEqual(stdout.getvalue(), outputs)
            self.assertEqual(stdin.read(), '')

    def test_sample_input_2(self):
        '''Run and assert problem statement sample 2 input and output.'''
        inputs = []
        inputs.append('2')
        inputs.append('1 4')
        inputs.append('2 2')
        inputs = '\n'.join(inputs) + '\n'

        outputs = '2.000000000\n'

        with patch('sys.stdin', io.StringIO(inputs)) as stdin,\
             patch('sys.stdout', new_callable=io.StringIO) as stdout:
            k_lipschitzconstant.main()
            self.assertEqual(stdout.getvalue(), outputs)
            self.assertEqual(stdin.read(), '')

    def test_sample_input_3(self):
        '''Run and assert problem statement sample 3 input and output.'''
        inputs = []
        inputs.append('4')
        inputs.append('-10 6.342')
        inputs.append('-7 3')
        inputs.append('46 18.1')
        inputs.append('2 -34')
        inputs = '\n'.join(inputs) + '\n'

        outputs = '4.111111111\n'

        with patch('sys.stdin', io.StringIO(inputs)) as stdin,\
             patch('sys.stdout', new_callable=io.StringIO) as stdout:
            k_lipschitzconstant.main()
            self.assertEqual(stdout.getvalue(), outputs)
            self.assertEqual(stdin.read(), '')

###############################################################################

if __name__ == '__main__':
    unittest.main()
