Skip to content
1,159 changes: 629 additions & 530 deletions data/open-eval.jsonl

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions data/raw/f_427_ming.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

KEYS = ['470FC614', '4A0FC614', '4B9FC614', '4C8FC614', '4D7FC614']


def f_427(hex_keys=KEYS, seed=42):
"""
Given a list of hexadecimal string keys, this function selects one at random,
Expand All @@ -21,15 +22,15 @@ def f_427(hex_keys=KEYS, seed=42):
ValueError: If contains invalid hexadecimal strings.

Requirements:
- struct: To unpack the hexadecimal string to a floating-point number.
- hashlib: To compute the MD5 hash of the floating-point number.
- random: To randomly select a hexadecimal string from the list.
- struct
- hashlib
- random

Example:
>>> f_427(['1a2b3c4d', '5e6f7g8h'])
'426614caa490f2c185aebf58f1d4adac'
"""

random.seed(seed)
hex_key = random.choice(hex_keys)

Expand All @@ -44,13 +45,15 @@ def f_427(hex_keys=KEYS, seed=42):

import unittest


def run_tests():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestF427))
suite.addTest(unittest.makeSuite(TestCases))
runner = unittest.TextTestRunner()
runner.run(suite)

class TestF427(unittest.TestCase):

class TestCases(unittest.TestCase):
def test_case_1(self):
result = f_427(['1a2b3c4d', '5e6f7g8h'])
self.assertEqual(result, '426614caa490f2c185aebf58f1d4adac')
Expand All @@ -71,8 +74,9 @@ def test_case_5(self):
# test error message
with self.assertRaises(ValueError):
f_427(['1a2b3c4d', '5e6f7g8h', 'invalid_hex'])



if __name__ == "__main__":
import doctest
doctest.testmod()
doctest.testmod(verbose=True)
run_tests()
1 change: 1 addition & 0 deletions data/raw/f_428_ming.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import binascii
import os
import base64

Expand Down
15 changes: 12 additions & 3 deletions data/raw/f_431_ming.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

def f_431(password: str, salt_length: int = 8) -> str:
'''
"""
Encrypt a password using Salt and SHA-256, then encode the result in base64.

Parameters:
Expand All @@ -19,8 +19,9 @@ def f_431(password: str, salt_length: int = 8) -> str:
- os

Example:
>>> f_431('my_password')
'''
>>> isinstance(f_431('my_password'), str)
True
"""
# Generate a random salt
salt = os.urandom(salt_length)
# Use the salt and the password to create a SHA-256 hash
Expand Down Expand Up @@ -73,5 +74,13 @@ def test_empty_password(self):
encrypted = f_431("")
self.assertTrue(isinstance(encrypted, str) and len(encrypted) > 0)

def run_tests():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCases))
runner = unittest.TextTestRunner()
runner.run(suite)

if __name__ == "__main__":
import doctest
doctest.testmod()
run_tests()
2 changes: 1 addition & 1 deletion data/raw/f_432_ming.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TestCases(unittest.TestCase):
def test_case_1(self):
random.seed(1)
result = f_432()
self.assertEqual(result, 'eJxzNTH0CgqMMHJxMgkwdAyM8rQwc3IMMffzCHDyCAjy9PQI9HY0CY1wtzRx9YmKMg8wjgQAWN0NxA==')
self.assertEqual(result, 'eJwFwUEOhCAMAMAvLVBXONJooGqkUCDa/z/EmR3M0epjNwQ2sSr5P8a+3pkxcyPK9YwwnhRgv1RXdu85F5CJZEvq+t4sVkpD1DBLkmA6kPhRj+6jdcvPyeAPdLQbtg==')

def test_case_2(self):
random.seed(0)
Expand Down
15 changes: 12 additions & 3 deletions data/raw/f_433_ming.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def f_433(df):
import unittest
from io import StringIO

class TestF433(unittest.TestCase):
class TestCases(unittest.TestCase):
def test_encode_basic_dataframe(self):
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
encoded_df = f_433(df)
Expand All @@ -52,7 +52,7 @@ def test_encode_empty_dataframe(self):
df = pd.DataFrame({'X': [], 'Y': []})
encoded_df = f_433(df)
decoded_csv = pd.read_csv(StringIO(base64.b64decode(encoded_df.encode('utf-8')).decode('utf-8')))
pd.testing.assert_frame_equal(df, decoded_csv, check_dtype=False)
pd.testing.assert_frame_equal(df, decoded_csv, check_dtype=False, check_index_type=False)

def test_encode_with_specific_values(self):
df = pd.DataFrame({'ID': [101, 102, 103], 'Score': [85, 90, 88]})
Expand All @@ -67,5 +67,14 @@ def test_encode_with_string_values(self):
pd.testing.assert_frame_equal(df, decoded_csv)


def run_tests():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCases))
runner = unittest.TextTestRunner()
runner.run(suite)


if __name__ == "__main__":
unittest.main()
import doctest
doctest.testmod()
run_tests()
12 changes: 7 additions & 5 deletions data/raw/f_434_ming.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ def f_434(list_of_menuitems):
- pandas

Example:
>>> f_434([['Pizza', 'Burger'], ['Pizza', 'Coke'], ['Pasta', 'Coke']])
Count
Pizza 2
Burger 1
Coke 2
>>> result = f_434([['Pizza', 'Burger'], ['Pizza', 'Coke'], ['Pasta', 'Coke']])
>>> result.loc['Pizza', 'Count']
2
>>> result.loc['Coke', 'Count']
2
"""
# Flattening the list using list comprehension
flat_list = [item for sublist in list_of_menuitems for item in sublist]
Expand Down Expand Up @@ -76,4 +76,6 @@ def test_case_5(self):


if __name__ == "__main__":
import doctest
doctest.testmod()
run_tests()
39 changes: 31 additions & 8 deletions data/raw/f_435_ming.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import Counter

import matplotlib
# Force matplotlib to use a non-GUI backend to prevent issues in environments without display capabilities
matplotlib.use('Agg')
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
Expand All @@ -15,7 +16,7 @@ def f_435(list_of_menuitems):
list_of_menuitems (list): A nested list of menu items.

Returns:
matplotlib.axes.Axes: An Axes object representing the visualization.
matplotlib.axes.Axes: An Axes object representing the visualization, or None if there are no items to plot.

Requirements:
- collections
Expand All @@ -28,14 +29,27 @@ def f_435(list_of_menuitems):
>>> isinstance(ax, matplotlib.axes.Axes)
True
"""
if not list_of_menuitems or not any(list_of_menuitems):
print("No items to plot.")
return None

# Flatten the nested list into a single list of items
flat_list = [item for sublist in list_of_menuitems for item in sublist]
if not flat_list:
print("No items to plot.")
return None

# Count the occurrence of each item
counter = Counter(flat_list)

# Convert the counter to a DataFrame
df = pd.DataFrame(counter.items(), columns=['Item', 'Count'])

# Ensure there is data to plot
if df.empty:
print("No items to plot.")
return None

# Create a seaborn barplot
sns.set(style="whitegrid")
ax = sns.barplot(x="Count", y="Item", data=df, palette="viridis")
Expand All @@ -46,7 +60,7 @@ def f_435(list_of_menuitems):

import unittest

class TestF435(unittest.TestCase):
class TestCases(unittest.TestCase):
def setUp(self):
# Set up any repeated data here
self.menu_items = [['Pizza', 'Burger'], ['Pizza', 'Coke'], ['Pasta', 'Coke']]
Expand All @@ -57,10 +71,9 @@ def test_return_type(self):
self.assertTrue(isinstance(ax, matplotlib.axes.Axes))

def test_empty_list(self):
"""Test the function with an empty list."""
"""Test the function with an empty list, expecting None as there's nothing to plot."""
ax = f_435([])
self.assertTrue(isinstance(ax, matplotlib.axes.Axes))
# Additional checks can be added for the properties of `ax` to ensure it's handling empty data gracefully
self.assertIsNone(ax)

def test_single_item_list(self):
"""Test the function with a list containing a single menu item."""
Expand All @@ -80,7 +93,17 @@ def test_multiple_items_same_count(self):
self.assertTrue(isinstance(ax, matplotlib.axes.Axes))
# Verifying that 'Soda' and 'Water' both appear and have the same count could be done here

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

def run_tests():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCases))
runner = unittest.TextTestRunner()
runner.run(suite)


if __name__ == "__main__":
import doctest
doctest.testmod()
run_tests()


Loading