def test_size_when_empty_myarray(self):
        # Arrange
        myarray = MyArray()

        # Act
        size = myarray.size()

        # Assert
        self.assertEqual(0, size)
    def test_size_when_more_than_one_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 100, 200)

        # Act
        size = myarray.size()

        # Assert
        self.assertEqual(2, size)
    def test_get_when_single_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 100)

        # Act
        element = myarray.get(0)

        # Assert
        self.assertEqual(100, element)
Exemple #4
0
    def test_pop_when_single_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 20)

        # Act
        myarray.pop()

        # Assert
        self.assertEqual(0, myarray.size())
    def test_set_when_single_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 100)

        # Act
        myarray.set(0, 200)

        # Assert
        self.assertEqual(200, myarray.get(0))
    def test_set_when_more_than_one_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 100, 200)

        # Act
        myarray.set(1, 300)

        # Assert
        self.assertEqual(300, myarray.get(1))
    def test_size_when_single_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 100)

        # Act
        size = myarray.size()

        # Assert
        self.assertEqual(1, size)
Exemple #8
0
 def __init__(self, num):
     """
     A method that initializes array of arrays.
     :param num: Sets length of table
     """
     self.num = num
     tempArr = MyArray(num)
     for i in range(num):
         tempArr[i] = MyArray(num)
     self.hash_table = tempArr
    def test_get_when_more_than_one_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 100, 200)

        # Act
        element_1 = myarray.get(0)
        element_2 = myarray.get(1)

        # Assert
        self.assertEqual(100, element_1)
        self.assertEqual(200, element_2)
Exemple #10
0
    def test_insert_when_single_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 20)

        # Act
        myarray.insert(0, 100)

        # Assert
        self.assertEqual(2, myarray.size())
        self.assertEqual(100, myarray.get(0))
        self.assertEqual(20, myarray.get(1))
    def test_append_when_more_than_one_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 100, 200)

        # Act
        myarray.append(300)

        # Assert
        self.assertEqual(3, myarray.size())
        self.assertEqual(100, myarray.get(0))
        self.assertEqual(200, myarray.get(1))
        self.assertEqual(300, myarray.get(2))
    def test_insert_when_more_than_one_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 1, 2, 3, 4, 5)

        # Act
        myarray.insert(2, 99)

        # Assert
        self.assertEqual(6, myarray.size())  # (expected, actual)
        self.assertEqual(99, myarray.get(2))
    def test_insert_when_single_item_myarray(self):
        # Arrange
        myarray = MyArray('i', 1)

        # Act
        myarray.insert(0, 99)

        # Assert
        self.assertEqual(2, myarray.size())  # (expected, actual)
        self.assertEqual(99, myarray.get(0))
Exemple #14
0
    def test_pop_when_more_than_one_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 20, 30)

        # Act
        myarray.pop(0)

        # Assert
        self.assertEqual(1, myarray.size())
        self.assertEqual(30, myarray.get(0))
    def test_insert_when_empty_myarray(self):
        # Arrange
        myarray = MyArray('i')

        # Act
        myarray.insert(0, 99)

        # Assert
        self.assertEqual(1, myarray.size())
        self.assertEqual(99, myarray.get(0))
    def test_append_when_empty_myarray(self):
        # Arrange
        myarray = MyArray('i')

        # Act
        myarray.append(100)

        # Assert
        self.assertEqual(1, myarray.size())
        self.assertEqual(100, myarray.get(0))
Exemple #17
0
    def test_pop_when_more_than_two_element_in_myarray(self):
        # Arrange
        myarray = MyArray('i', 20, 30, 40)

        # Act
        myarray.pop(1)

        # Assert
        self.assertEqual(2, myarray.size())
        self.assertEqual(20, myarray.get(0))
        self.assertEqual(40, myarray.get(1))
Exemple #18
0
 def __init__(self):
     """
     Produces a newly constructed empty Multiset.
     """
     self.data = MyArray(100)
     self.firstempty = 0
Exemple #19
0
import myfile as file
from myarray import MyArray

correct = file.read('correct.csv')
inputs = file.read('data.csv')

x = MyArray([-1, -1, -1])
rate = 0.2


def output(w, x):

    tmp = w * x
    value = tmp.sum()

    return (1 if value >= 0 else -1)


def learn(w, rate, x, flg):
    return (w + rate * flg * x)


for (i, value) in enumerate(inputs):
    print(output(w, value))

for count in range(1):

    for (i, value) in enumerate(inputs):
        out = output(w, value)

        if out != correct[i].v(0):
Exemple #20
0
    def test_remove_when_empty_myarray(self):
        # Arrange
        myarray = MyArray()

        # Act & Assert
        self.assertRaises(ValueError, myarray.remove, 100)
    def test_set_when_empty_myarray(self):
        # Arrange
        myarray = MyArray('i')

        # Act & Assert
        self.assertRaises(IndexError, myarray.set, 0, 100)
Exemple #22
0
    def test_pop_when_empty_myarray(self):
        # Arrange
        myarray = MyArray()

        # Act & Assert
        self.assertRaises(IndexError, myarray.pop, -1)
Exemple #23
0
    def test_pop_when_index_out_bounds(self):
        # Arrange
        myarray = MyArray('i', 20, 30, 40)

        # Act & Assert
        self.assertRaises(IndexError, myarray.pop, 4)
Exemple #24
0
from myarray import MyArray

x = MyArray([1.0,2.0,3.0])
y = x.array()
y[0]
x = 'foo'
y[0]

    def test_get_when_empty_myarray(self):
        # Arrange
        myarray = MyArray()

        # Act & Assert
        self.assertRaises(IndexError, myarray.get, 0)