コード例 #1
0
    def test_solution(self):
        from build import solution

        dic1 = {10:1, 20:2, 30:3}
        key1 = 10
        key2 = 40
        res1 = solution(dic1, key1)
        res2 = solution(dic1, key2)

        self.assertEqual(res1, True)
        self.assertEqual(res2, False)
コード例 #2
0
    def test_solution(self):
        from build import solution

        dic1 = {1:10, 2:20, 3:30}
        key1 = 2
        key2 = 4
        res1 = solution(dic1, key1)
        res2 = solution(dic1, key2)

        self.assertEqual(res1.get(key1), None)
        self.assertEqual(res2, dic1)
コード例 #3
0
    def test_solution(self):
        from build import solution

        fpath = "./files/testfile.txt"
        solution(fpath)

        with open(fpath, 'r') as f:
            if '\n' in f.read():
                res = True
            else:
                res = False

        self.assertEqual(False, res)
コード例 #4
0
    def test_solution(self):
        from build import solution
        from random import randint

        num1 = randint(100, 1000)
        num2 = randint(100, 1000)
        num3 = randint(100, 1000)
        num4 = randint(100, 1000)

        l = [num1, num2, num3, num4]

        self.assertTrue(solution(l)[0], num1)
        self.assertTrue(solution(l)[0], num2)
        self.assertTrue(solution(l)[0], num3)
        self.assertTrue(solution(l)[0], num4)
コード例 #5
0
    def test_solution(self):
        from build import solution

        a_list = [1, 2, -8, -2, 0]
        result = solution(a_list)

        self.assertEqual(result, -2)
コード例 #6
0
    def test_solution(self):
        from build import solution

        result = solution([1, 2, 5, 4], 3)
        expected = [1, 2, 3, 4, 5]

        self.assertEqual(result, expected)
コード例 #7
0
    def test_solution(self):
        from build import solution

        x = [45, 38, 52, 48, 25, 39, 51, 46, 55, 46]
        y = [34, 22, 15, 27, 37, 41, 24, 19, 26, 36]

        self.assertTrue(solution(x, y, 0.05))
コード例 #8
0
    def test_solution(self):
        from build import solution

        dic = {1: 10, 2: 20, 3: 30}
        res = solution(dic)

        self.assertEqual(res, 60)
コード例 #9
0
    def test_solution(self):
        from build import solution

        res = solution([1, 2, 3, 5, 8, 9])

        self.assertEqual(res['ODD'], 4)
        self.assertEqual(res['EVEN'], 2)
コード例 #10
0
    def test_solution(self):
        from build import solution

        fpath = './files/testfile.txt'
        res = solution(fpath)

        self.assertEqual(res, 5)
コード例 #11
0
    def test_solution(self):
        from build import solution
        import os

        res = solution('./files/testfile.txt')

        self.assertEqual(res, 717)
コード例 #12
0
    def test_solution(self):
        from build import solution

        filepath = "./files/hello.txt"
        res = solution(filepath)

        self.assertEqual('Hello World!\n', res)
        self.assertIsInstance(res, str)
コード例 #13
0
    def test_solution(self):
        from build import solution
        num1 = 2
        num2 = 3
        end_num = 19
        res = solution(num1, num2, end_num)

        self.assertItemsEqual(res, [6, 12, 18])
コード例 #14
0
    def test_solution(self):
        from build import solution

        fpath = './files/testfile.txt'
        res = solution(fpath)

        self.assertEqual(res[0], 'This is the first line.')
        self.assertEqual(len(res), 3)
コード例 #15
0
    def test_solution(self):
        from build import solution
        from random import randint
        random_number = randint(0, 9)
        dic = {'k1': [1, 2, 3, {'tricky': ['oh', 'man', 'inception', {'target': [1, 2, 3, random_number]}]}]}
        last_index_of_target = solution(dic)

        self.assertEqual(last_index_of_target, random_number)
コード例 #16
0
    def test_solution(self):
        from build import solution

        res = solution()

        self.assertEqual(['b', 'd', 'f'], res.index.tolist())
        self.assertEqual(res['name']['b'], 'Dima')
        self.assertEqual(res['name']['d'], 'James')
        self.assertEqual(res['name']['f'], 'Michael')
コード例 #17
0
    def test_solution(self):
        from build import solution

        thelist = [10, 20, 30]
        res = solution(thelist)
        ans = [[], [10], [20], [30], [10, 30], [10, 20], [20, 30],
               [10, 20, 30]]
        self.assertEqual(8, len(res))
        self.assertItemsEqual(res, ans)
コード例 #18
0
    def test_solution(self):
        from build import solution
        import numpy as np
        res = solution()

        self.assertEqual(res['name']['a'], 'Anastasia')
        self.assertEqual(res['name']['j'], 'Jonas')

        self.assertEqual(res['score']['i'], 8.0)
        self.assertEqual(res['score']['c'], 16.5)
コード例 #19
0
    def test_solution(self):
        from build import solution

        dic = {'x': 500, 'y': 5874, 'z': 560}
        maxvalue = 5874
        minvalue = 500
        result = solution(dic)

        self.assertEqual(result[0], maxvalue)
        self.assertEqual(result[1], minvalue)
コード例 #20
0
    def test_solution(self):
        from build import solution

        res = solution()
        list_res = list(res)
        res3 = list_res[:]
        res3.sort()

        self.assertEqual(res.shape, (10, ))
        self.assertEqual(list_res, res3)
コード例 #21
0
    def test_solution(self):
        from build import solution
        from random import randint
        num1 = randint(0, 9)
        num2 = randint(0, 9)
        num3 = randint(0, 9)

        result = solution([num1,num2,num3])

        self.assertEqual(result, num1+num2+num3)
コード例 #22
0
    def test_solution(self):
        from build import solution

        keys = [1, 2, 3]
        values = [10, 20, 30]
        res = solution(keys, values)

        self.assertEqual(res[1], 10)
        self.assertEqual(res[2], 20)
        self.assertEqual(res[3], 30)
コード例 #23
0
    def test_solution(self):
        from build import solution
        from random import randint
        import pandas as pd
        num1 = randint(0, 100)
        array = [num1]

        res = solution(array)
        self.assertTrue(isinstance(res, pd.Series))
        self.assertEqual(num1, res[0])
コード例 #24
0
    def test_solution(self):
        from build import solution
        from collections import Counter

        fpath = './files/testfile.txt'
        res = solution(fpath)

        self.assertEqual(res['Python'], 3)
        self.assertEqual(res['and'], 6)
        self.assertIsInstance(res, Counter)
コード例 #25
0
    def test_solution(self):
        from build import solution
        import pandas as pd
        from random import randint
        num1 = randint(0, 100)
        ds = pd.Series([num1])
        res = solution(ds)

        self.assertTrue(isinstance(res, list))
        self.assertEqual(num1, res[0])
コード例 #26
0
    def test_solution(self):
        from build import solution

        dic1 = {1: 10, 2: 20, 3: 30, 4: 40}
        res = solution(dic1)

        self.assertEqual(res[0], (1, 10))
        self.assertEqual(res[1], (2, 20))
        self.assertEqual(res[2], (3, 30))
        self.assertEqual(res[3], (4, 40))
コード例 #27
0
    def test_solution(self):
        from build import solution

        d1 = {'a': 100, 'b': 200, 'c': 300}
        d2 = {'a': 300, 'b': 200, 'd': 400}
        result = solution(d1, d2)
        self.assertEqual(result['a'], 400)
        self.assertEqual(result['b'], 400)
        self.assertEqual(result['c'], 300)
        self.assertEqual(result['d'], 400)
コード例 #28
0
    def test_solution(self):
        from build import solution

        fpath = './files/lines.txt'
        n = 3
        res = solution(fpath, n)

        self.assertEqual(res[0], 'This is line one.')
        self.assertEqual(res[1], 'This is line two.')
        self.assertEqual(len(res), 3)
        self.assertIsInstance(res, list)
コード例 #29
0
    def test_solution(self):
        from build import solution
        from random import randint

        fpath = './files/testfile.txt'
        n = randint(1, 5)
        res = solution(fpath, n)

        self.assertEqual(res[-1], 'This is the last line.')
        self.assertEqual(len(res), n)
        self.assertIsInstance(res, list)
コード例 #30
0
    def test_solution_same_keys(self):
        from build import solution

        dict1 = {1: 10, 2: 20}
        dict2 = {2: 30, 4: 40}

        res = solution(dict1, dict2)

        self.assertEqual(10, res[1])
        self.assertEqual(30, res[2])
        self.assertEqual(40, res[4])
コード例 #31
0
    def test_solution(self):
        from build import solution
        from sklearn import datasets, svm, metrics

        digits = datasets.load_digits()
        n_samples = len(digits.images)
        data = digits.images.reshape((n_samples, -1))
        clf = solution()
        expected = digits.target[n_samples // 2:]
        predicted = clf.predict(data[n_samples // 2:])

        self.assertAlmostEqual(metrics.accuracy_score(expected, predicted), 0.968854282536 , places=3)