Skip to content

Commit

Permalink
fix: update 1031 solution and test
Browse files Browse the repository at this point in the history
  • Loading branch information
terryyz committed May 11, 2024
1 parent 430e1c2 commit a4498d9
Show file tree
Hide file tree
Showing 5 changed files with 1,105 additions and 1,110 deletions.
23 changes: 10 additions & 13 deletions data/clean/f_1031_zhihan_refined.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ def f_1031(list_of_pairs):
>>> print(product_array)
360
"""
# Extract the second element from each tuple using a list comprehension
values = [pair[1] for pair in list_of_pairs]

# Use reduce to calculate the product of all elements in the values list
product = reduce(lambda x, y: x * y, values)

# Return the result as a numpy array with a single element
return np.array([product])
second_values = [pair[1] for pair in list_of_pairs]
product = reduce(np.multiply, second_values)
product_array = np.array([product])

return product_array

import unittest
import numpy as np
Expand All @@ -46,36 +43,36 @@ class TestCases(unittest.TestCase):
def test_case_1(self):
# Basic test case with positive and negative numbers
list_of_pairs = [('Fruits', 5), ('Vegetables', 9), ('Dairy', -1), ('Bakery', -2), ('Meat', 4)]
expected_output = np.array(360)
expected_output = np.array([360])
actual_output = f_1031(list_of_pairs)
print(actual_output, expected_output)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_2(self):
# Test case with all positive numbers
list_of_pairs = [('A', 2), ('B', 3), ('C', 4)]
expected_output = np.array(24)
expected_output = np.array([24])
actual_output = f_1031(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_3(self):
# Test case with all negative numbers
list_of_pairs = [('A', -2), ('B', -3), ('C', -4)]
expected_output = np.array(-24)
expected_output = np.array([-24])
actual_output = f_1031(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_4(self):
# Test case with a single tuple
list_of_pairs = [('A', 10)]
expected_output = np.array(10)
expected_output = np.array([10])
actual_output = f_1031(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_5(self):
# Test case with zeros
list_of_pairs = [('A', 0), ('B', 5), ('C', 10)]
expected_output = np.array(0)
expected_output = np.array([0])
actual_output = f_1031(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))
if __name__ == "__main__":
Expand Down
17 changes: 9 additions & 8 deletions data/processed/33_w_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ def task_func(list_of_pairs):
>>> print(product_array)
360
"""
values = [pair[1] for pair in list_of_pairs]
product = reduce(lambda x, y: x * y, values)
return np.array([product])
second_values = [pair[1] for pair in list_of_pairs]
product = reduce(np.multiply, second_values)
product_array = np.array([product])
return product_array

import unittest
import numpy as np
Expand All @@ -34,35 +35,35 @@ class TestCases(unittest.TestCase):
def test_case_1(self):
# Basic test case with positive and negative numbers
list_of_pairs = [('Fruits', 5), ('Vegetables', 9), ('Dairy', -1), ('Bakery', -2), ('Meat', 4)]
expected_output = np.array(360)
expected_output = np.array([360])
actual_output = task_func(list_of_pairs)
print(actual_output, expected_output)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_2(self):
# Test case with all positive numbers
list_of_pairs = [('A', 2), ('B', 3), ('C', 4)]
expected_output = np.array(24)
expected_output = np.array([24])
actual_output = task_func(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_3(self):
# Test case with all negative numbers
list_of_pairs = [('A', -2), ('B', -3), ('C', -4)]
expected_output = np.array(-24)
expected_output = np.array([-24])
actual_output = task_func(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_4(self):
# Test case with a single tuple
list_of_pairs = [('A', 10)]
expected_output = np.array(10)
expected_output = np.array([10])
actual_output = task_func(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_5(self):
# Test case with zeros
list_of_pairs = [('A', 0), ('B', 5), ('C', 10)]
expected_output = np.array(0)
expected_output = np.array([0])
actual_output = task_func(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))
23 changes: 10 additions & 13 deletions data/raw/f_1031_zhihan_refined.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@ def f_1031(list_of_pairs):
>>> print(product_array)
360
"""
# Extract the second element from each tuple using a list comprehension
values = [pair[1] for pair in list_of_pairs]

# Use reduce to calculate the product of all elements in the values list
product = reduce(lambda x, y: x * y, values)

# Return the result as a numpy array with a single element
return np.array([product])
second_values = [pair[1] for pair in list_of_pairs]
product = reduce(np.multiply, second_values)
product_array = np.array([product])

return product_array

import unittest
import numpy as np
Expand All @@ -46,36 +43,36 @@ class TestCases(unittest.TestCase):
def test_case_1(self):
# Basic test case with positive and negative numbers
list_of_pairs = [('Fruits', 5), ('Vegetables', 9), ('Dairy', -1), ('Bakery', -2), ('Meat', 4)]
expected_output = np.array(360)
expected_output = np.array([360])
actual_output = f_1031(list_of_pairs)
print(actual_output, expected_output)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_2(self):
# Test case with all positive numbers
list_of_pairs = [('A', 2), ('B', 3), ('C', 4)]
expected_output = np.array(24)
expected_output = np.array([24])
actual_output = f_1031(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_3(self):
# Test case with all negative numbers
list_of_pairs = [('A', -2), ('B', -3), ('C', -4)]
expected_output = np.array(-24)
expected_output = np.array([-24])
actual_output = f_1031(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_4(self):
# Test case with a single tuple
list_of_pairs = [('A', 10)]
expected_output = np.array(10)
expected_output = np.array([10])
actual_output = f_1031(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))

def test_case_5(self):
# Test case with zeros
list_of_pairs = [('A', 0), ('B', 5), ('C', 10)]
expected_output = np.array(0)
expected_output = np.array([0])
actual_output = f_1031(list_of_pairs)
self.assertTrue(np.array_equal(actual_output, expected_output))
if __name__ == "__main__":
Expand Down
Loading

0 comments on commit a4498d9

Please sign in to comment.