def test_case_4():
    test_log("testing predicates")
    tc = TestCase()
    lst = ArrayList()
    lst2 = ArrayList()

    lst.data = ConstrainedList.create([])
    lst.len = len(lst.data)
    lst2.data = ConstrainedList.create([1, 2, 3])
    lst2.len = len(lst2.data)
    tc.assertNotEqual(lst, lst2)

    lst.data = ConstrainedList.create([1, 2, 3])
    lst.len = len(lst.data)
    tc.assertEqual(lst, lst2)

    lst.data = ConstrainedList.create([])
    lst.len = len(lst.data)
    tc.assertFalse(1 in lst)
    tc.assertFalse(None in lst)

    lst.data = ConstrainedList.create(range(100))
    lst.len = len(lst.data)
    tc.assertFalse(100 in lst)
    tc.assertTrue(50 in lst)
    suc()
def _assert_not_equal_fingerprints(
    test_case: unittest.TestCase, schema_text1: str, schema_text2: str
):
    """Parse the schema texts and assert that the schemas do not have the same fingerprint."""
    fingerprint1 = _compute_schema_text_fingerprint(schema_text1)
    fingerprint2 = _compute_schema_text_fingerprint(schema_text2)
    test_case.assertNotEqual(fingerprint1, fingerprint2)
Exemple #3
0
def test_gj_Solve():
    for _ in range(9999):
        r = np.random.randint(low=3, high=10)
        A = np.random.randint(low=-10, high=10, size=(r, r))
        b = np.arange(r).reshape((r, 1))

        x = gj_Solve(A.tolist(), b.tolist(), epsilon=1.0e-8)

        if np.linalg.matrix_rank(A) < r:
            TestCase.assertEqual(x, None, "Matrix A is singular")
        else:
            TestCase.assertNotEqual(x, None, "Matrix A is not singular")
            TestCase.assertEqual(np.array(x).shape, (r, 1),
                             "Expected shape({},1), but got shape{}".format(r, np.array(x).shape))
            Ax = np.dot(A, np.array(x))
            loss = np.mean((Ax - b) ** 2)
            TestCase.assertTrue(loss < 0.1, "Bad result.")
Exemple #4
0
def check_response(test: unittest.TestCase,
                   res: requests.Response,
                   content_type: str = None):
    res_data = None
    if content_type is None:
        test.assertNotIn('Content-Type', res.headers)
    else:
        test.assertIn('Content-Type', res.headers)
        test.assertEqual(res.headers['Content-Type'],
                         content_type + '; charset=utf-8')
        test.assertNotEqual(len(res.text), 0)
        if content_type == 'text/html':
            res_data = res.text
        elif content_type == 'application/json':
            res_data = res.json()
        else:
            raise ValueError()
    return res_data
def test_predicates():
    say_test("test_predicates")
    tc = TestCase()
    lst = LinkedList()
    lst2 = LinkedList()

    tc.assertEqual(lst, lst2)

    lst2.append(100)
    tc.assertNotEqual(lst, lst2)
    lst.append(100)
    tc.assertEqual(lst, lst2)

    tc.assertFalse(1 in lst)
    tc.assertFalse(None in lst)

    lst = LinkedList()
    for i in range(100):
        lst.append(i)
    tc.assertFalse(100 in lst)
    tc.assertTrue(50 in lst)
Exemple #6
0
    def test_onTheFlyDeclarations(self):
        xb = self.res.getVarInlist("xb")
        xa0 = self.res.getVarInlist("xa0")
        TestCase.assertNotEqual(self, xb, None)
        TestCase.assertNotEqual(self, xa0, None)

        noncem = self.res.getTypeInlist("noncem")
        noncek = self.res.getTypeInlist("noncek")
        TestCase.assertNotEqual(self, noncem, None)
        TestCase.assertNotEqual(self, noncek, None)

        TestCase.assertTrue(self, xb.onTheFly)
        TestCase.assertTrue(self, xa0.onTheFly)
        TestCase.assertEqual(self, xb.type, noncek)
        TestCase.assertEqual(self, xa0.type, noncem)

        TestCase.assertFalse(self, noncem.public)
        TestCase.assertFalse(self, noncek.public)
        TestCase.assertFalse(self, noncem.honest)
        TestCase.assertFalse(self, noncek.honest)
Exemple #7
0
    def test_privateDeclarations(self):
        ska = self.res.getVarInlist("ska")
        k0 = self.res.getVarInlist("k0")
        n1 = self.res.getVarInlist("n1")
        TestCase.assertNotEqual(self, ska, None)
        TestCase.assertNotEqual(self, self.res.getVarInlist("skb"), None)
        TestCase.assertNotEqual(self, self.res.getVarInlist("skc"), None)
        TestCase.assertNotEqual(self, k0, None)
        TestCase.assertNotEqual(self, n1, None)

        noncem = self.res.getTypeInlist("noncem")
        kaenca = self.res.getTypeInlist("kaenca")
        noncek = self.res.getTypeInlist("noncek")
        TestCase.assertNotEqual(self, noncem, None)
        TestCase.assertNotEqual(self, kaenca, None)
        TestCase.assertNotEqual(self, self.res.getTypeInlist("kaencb"), None)
        TestCase.assertNotEqual(self, self.res.getTypeInlist("kaencc"), None)
        TestCase.assertNotEqual(self, noncek, None)

        TestCase.assertFalse(self, k0.onTheFly)
        TestCase.assertFalse(self, n1.onTheFly)
        TestCase.assertFalse(self, ska.onTheFly)
        TestCase.assertEqual(self, ska.type, kaenca)
        TestCase.assertEqual(self, k0.type, noncek)
        TestCase.assertEqual(self, n1.type, noncem)

        TestCase.assertFalse(self, noncem.public)
        TestCase.assertFalse(self, kaenca.public)
        TestCase.assertFalse(self, noncek.public)
        TestCase.assertFalse(self, noncem.honest)
        TestCase.assertTrue(self, kaenca.honest)
        TestCase.assertFalse(self, noncek.honest)
Exemple #8
0
    def test_publicDeclarations(self):
        a = self.res.getVarInlist("a")
        TestCase.assertNotEqual(self, a, None)
        TestCase.assertNotEqual(self, self.res.getVarInlist("b"), None)
        TestCase.assertNotEqual(self, self.res.getVarInlist("c"), None)

        typea = self.res.getTypeInlist("typea")
        TestCase.assertNotEqual(self, typea, None)
        TestCase.assertNotEqual(self, self.res.getTypeInlist("typeb"), None)
        TestCase.assertNotEqual(self, self.res.getTypeInlist("typec"), None)

        TestCase.assertFalse(self, a.onTheFly)
        TestCase.assertEqual(self, a.type, typea)
        TestCase.assertTrue(self, typea.public)
        TestCase.assertFalse(self, typea.honest)
    lst.remove(9999)


# In[208]:


# (4 points) test predicates

from unittest import TestCase
tc = TestCase()
lst = ArrayList()
lst2 = ArrayList()

lst.data = ConstrainedList([])
lst2.data = ConstrainedList([1, 2, 3])
tc.assertNotEqual(lst, lst2)

lst.data = ConstrainedList([1, 2, 3])
tc.assertEqual(lst, lst2)

lst.data = ConstrainedList([])
tc.assertFalse(1 in lst)
tc.assertFalse(None in lst)

lst.data = ConstrainedList(range(100))
tc.assertFalse(100 in lst)
tc.assertTrue(50 in lst)


# In[209]:
Exemple #10
0
def should_not_equal(test: unittest.TestCase, except_value, real_value):
    return test.assertNotEqual(except_value, real_value)
Exemple #11
0
class WebRequestTest(WebRequest, TestCase):

    ERROR_MSG = 'Error Message:  '
    START_TEST = 'StartingTest'
    STOP_TEST = 'StoppingTest'

    def __init__(self):
        super().__init__()
        self.test = TestCase()

    def clear_request_data(self):
        self.url = ''
        self.url_padding = ''
        del self.recursive_urls[:]
        self.request_data = None
        self.requests_status_code = None
        del self.recursive_request_data[:]
        self.recursive_request_data_count = 0

    def print_test_title(self, text, number):
        self.view.display_item('----------------' + text + '::' + number +
                               '----------------')

    # All WebRequest unit tests below

    def set_url_test_one(self):
        self.print_test_title(self.START_TEST, '1.1')
        url = 'http://www.google.com'
        self.set_url(url)
        self.test.assertEqual(self.url, url,
                              self.ERROR_MSG + 'url no equal to set value')

    def set_url_test_two(self):
        self.print_test_title(self.START_TEST, '1.2')
        url = 'google.com'
        self.set_url(url)
        self.test.assertNotEqual(self.url, url,
                                 self.ERROR_MSG + 'url equal to set value')

    def set_url_padding_test_one(self):
        self.print_test_title(self.START_TEST, '2.1')
        url_padding = 'http://www.google.com'
        self.set_url_padding(url_padding)
        self.test.assertEqual(
            self.url_padding, url_padding,
            self.ERROR_MSG + 'url padding not equal to set value')

    def set_url_padding_test_two(self):
        self.print_test_title(self.START_TEST, '2.2')
        url_padding = 'google.com'
        self.set_url_padding(url_padding)
        self.test.assertNotEqual(
            self.url_padding, url_padding,
            self.ERROR_MSG + 'url padding equal to padding value')

    def add_recursive_url_test_one(self):
        self.print_test_title(self.START_TEST, '3.1')
        self.clear_request_data()
        rec_url = 'http://www.google.com'
        self.add_recursive_url(rec_url)
        self.test.assertEqual(self.recursive_urls[0], rec_url,
                              self.ERROR_MSG + 'recursive url not in list')

    def add_recursive_url_test_two(self):
        self.print_test_title(self.START_TEST, '3.2')
        self.clear_request_data()
        rec_url = 'test'
        zero_urls = 0
        self.add_recursive_url(rec_url)
        self.test.assertEqual(len(self.recursive_urls), zero_urls,
                              self.ERROR_MSG + 'recursive url in list')

    def fetch_html_test_one(self):
        self.print_test_title(self.START_TEST, '4.1')
        self.clear_request_data()
        url = 'http://www.google.com'
        response_okay = 200
        self.set_url(url)
        self.fetch_html()
        self.test.assertEqual(
            self.requests_status_code, response_okay,
            self.ERROR_MSG + 'response code ' + str(self.requests_status_code))

    def fetch_html_test_two(self):
        self.print_test_title(self.START_TEST, '4.2')
        self.clear_request_data()
        url = 'http://www.thisisafakeurlsoyeah.com'
        response_okay = 200
        self.set_url(url)
        self.fetch_html()
        self.test.assertNotEqual(
            self.requests_status_code, response_okay,
            self.ERROR_MSG + 'response code ' + str(self.requests_status_code))

    def recursive_fetch_test_one(self):
        self.print_test_title(self.START_TEST, '5.1')
        self.clear_request_data()
        url = 'http://www.google.com'
        response_okay = 200
        self.add_recursive_url(url)
        self.add_recursive_url(url)
        self.recursive_fetch()
        self.test.assertEqual(
            self.requests_status_code, response_okay,
            self.ERROR_MSG + 'response code ' + str(self.requests_status_code))

    def recursive_fetch_test_two(self):
        self.print_test_title(self.START_TEST, '5.2')
        self.clear_request_data()
        url = 'http://www.thisisafakeurlsoyeah.com'
        response_okay = 200
        self.add_recursive_url(url)
        self.add_recursive_url(url)
        self.recursive_fetch()
        self.test.assertNotEqual(
            self.requests_status_code, response_okay,
            self.ERROR_MSG + 'response code ' + str(self.requests_status_code))