Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
eaed575
fix doctest output
imamnurby May 1, 2024
7efb244
[1030] refine docstring and implementation
imamnurby May 1, 2024
fde3229
[1030] refine test cases using setUp and tearDown method
imamnurby May 1, 2024
6fc2e42
[1029] refine docstring description and remove unused libraries
imamnurby May 1, 2024
0fd7f4e
fix bug in the VALID_JSON_STRUCTURE constant, refine testcases
imamnurby May 1, 2024
d234a04
refine docstring
imamnurby May 1, 2024
c994597
move out the test cases from run_test function, rename test class to …
imamnurby May 1, 2024
6a54fdd
fix docstring expected output
imamnurby May 1, 2024
e3b577d
improve test cases
imamnurby May 1, 2024
6c353b9
remove typing
imamnurby May 1, 2024
9ae63d5
refine docstring
imamnurby May 1, 2024
e901168
add a test case to check the payload
imamnurby May 1, 2024
e35882a
refine docstring
imamnurby May 1, 2024
999007e
rename unittest class
imamnurby May 1, 2024
9f93f4f
refine testcases
imamnurby May 1, 2024
1c4a053
refine docstring
imamnurby May 1, 2024
f141346
refine testcases
imamnurby May 1, 2024
6050eb0
refine docstring
imamnurby May 1, 2024
6dc6c56
refine testcases
imamnurby May 1, 2024
809f4cd
refine docstring
imamnurby May 1, 2024
8a76c49
refine testcases, add Raises in the docstring
imamnurby May 1, 2024
a72de9a
refine docstring
imamnurby May 1, 2024
4842b4f
refine testcases
imamnurby May 1, 2024
48b4b74
refine docstring
imamnurby May 1, 2024
52dc438
refine testcases
imamnurby May 1, 2024
bed6ad8
refine doctstring
imamnurby May 2, 2024
e6b8adf
refine testcases
imamnurby May 2, 2024
048d45c
refine docstring
imamnurby May 2, 2024
075897c
refine testcases
imamnurby May 2, 2024
5d79adb
refine docstring
imamnurby May 3, 2024
af2f47a
refine docstring and testcases
imamnurby May 3, 2024
3948747
refine docstring
imamnurby May 3, 2024
3c73dcf
refine testcases
imamnurby May 3, 2024
fd68ac1
remove unused import
imamnurby May 3, 2024
cef46b3
add import
imamnurby May 3, 2024
d0daeb0
refine docstring
imamnurby May 3, 2024
bcb42e4
refine testcases
imamnurby May 3, 2024
73469f4
refine docstring
imamnurby May 3, 2024
1f9d19a
refine docstring and testcases
imamnurby May 3, 2024
dbda3df
refine docstring and testcases
imamnurby May 3, 2024
62ece73
refine docstring
imamnurby May 3, 2024
f4f91f2
refine docstring
imamnurby May 4, 2024
3ea0517
refine testcases
imamnurby May 4, 2024
464cfd3
refine docstring
imamnurby May 4, 2024
c53df91
refine docstring
imamnurby May 4, 2024
5788154
refine testcases
imamnurby May 4, 2024
ff160e4
refine testcases
imamnurby May 4, 2024
ec8f2ef
refien docstring and testcases
imamnurby May 4, 2024
dc16c13
refine docstring
imamnurby May 4, 2024
6dbada6
refine docstring and testcases
imamnurby May 4, 2024
3e7cfc5
refine docstring
imamnurby May 4, 2024
04b0c12
refine testcases
imamnurby May 4, 2024
099cc79
refine testcases
imamnurby May 4, 2024
00b517b
refine docstring and testcases
imamnurby May 4, 2024
3b296da
refine docstring and testcases
imamnurby May 4, 2024
abc98d6
refine docstring and add statistics library
imamnurby May 4, 2024
fcfa0ae
refine testcases
imamnurby May 4, 2024
cb335b0
refine testcases, add Raises section in the docstring
imamnurby May 4, 2024
831b0dd
refine docstring and testcases, modify the implementation to use the …
imamnurby May 4, 2024
9a1f33b
refine docstring and testcases, add helper function to check mse value
imamnurby May 4, 2024
810293e
refine docstring and testcases
imamnurby May 4, 2024
e17b2fb
add docstring and refine testcases
imamnurby May 4, 2024
12eca2f
refine docstring and testcases
imamnurby May 4, 2024
fc358b9
refine docstring and testcases
imamnurby May 4, 2024
437bbe2
refine docstring and testcases
imamnurby May 4, 2024
f910eae
refine testcases and docstring
imamnurby May 5, 2024
0827422
refine docstring and testcases, add Raises
imamnurby May 5, 2024
2d6696a
refine docstring and move loading sql inside the function
imamnurby May 5, 2024
bea53e8
refine docstring and testcases
imamnurby May 5, 2024
ab7c50e
refine testcases and docstring
imamnurby May 6, 2024
9f5f78a
refine docstring and testcases
imamnurby May 6, 2024
0232eba
remove duplicate import statements and mock class
imamnurby May 6, 2024
5b48a67
add Requirements in the docstring
imamnurby May 6, 2024
c632a7a
remove print
imamnurby May 6, 2024
151f63e
remove print
imamnurby May 6, 2024
3335ec7
refine docstring
imamnurby May 6, 2024
f4648eb
fix implementation and refine testcases
imamnurby May 6, 2024
8ab7d08
refine docstring and testcases
imamnurby May 6, 2024
3b917e2
refine testcases
imamnurby May 6, 2024
c40f70f
refine docstring
imamnurby May 6, 2024
376fd52
refine and add more testcases, add missing import
imamnurby May 6, 2024
a79c547
refine docstring and testcases
imamnurby May 6, 2024
0bcdfa3
update the docstring
imamnurby May 6, 2024
a4299b5
refine testcases and docstring
imamnurby May 6, 2024
8911a3e
fix duplicate runner method, rename test class
imamnurby May 6, 2024
b539253
refine docstring and testcases
imamnurby May 6, 2024
86df211
refine docstring and testcases
imamnurby May 6, 2024
ebe6e10
refine docstring and testcases
imamnurby May 6, 2024
127b5aa
remove multiple import
imamnurby May 6, 2024
d354394
remove multiple import
imamnurby May 6, 2024
d2477c1
refine docstring
imamnurby May 6, 2024
bf77ef6
update example
imamnurby May 6, 2024
6da3bfe
remove duplicate import
imamnurby May 6, 2024
3d1d11e
remove comments
imamnurby May 6, 2024
8ab8219
remove duplicate import
imamnurby May 6, 2024
6c24263
update import
imamnurby May 6, 2024
248f4e4
add Raises section, make the testcases more deterministic
imamnurby May 6, 2024
5d732f3
change randint to random
imamnurby May 6, 2024
228e847
make the test more specific and deterministic
imamnurby May 6, 2024
687aa93
remove constant
imamnurby May 6, 2024
9c94bfd
refine docstring and testcases
imamnurby May 7, 2024
876026a
add Requirements in the docstring
imamnurby May 7, 2024
03157a0
remove explanation in Requirments
imamnurby May 7, 2024
8bbd4b8
fix indentation
imamnurby May 7, 2024
6285360
separte testcases
imamnurby May 7, 2024
fd604d0
move constant as the default param
imamnurby May 7, 2024
5d9af2d
Move THRESHOLD to optional param
imamnurby May 7, 2024
ade40b0
add type of K
imamnurby May 7, 2024
cb26fc2
move SALTH_LENGTH to optional param
imamnurby May 7, 2024
7702642
move DATE_FORMAT to optional param
imamnurby May 7, 2024
943584c
fix wrong argument in datetime.strptime in the testcase
imamnurby May 7, 2024
fb24d18
move VALID_JSON_STRUCTURE and EMAIL_REGEX to optional param
imamnurby May 7, 2024
cac15bc
Add default values in the docstring
imamnurby May 7, 2024
4222532
fix testcases
imamnurby May 7, 2024
afcb5ce
modify example in the docstring
imamnurby May 7, 2024
e4de8b0
remove unused import
imamnurby May 7, 2024
765695e
fix the example in the docstring
imamnurby May 7, 2024
37a0107
fix the example in the docstring
imamnurby May 7, 2024
7e9af83
add .db in check_test_wo_doc
imamnurby May 7, 2024
fad8c1f
add subprocess in check_test_wo_doc
imamnurby May 7, 2024
d840f31
separate the testcase to check the number of updated hash and the cor…
imamnurby May 7, 2024
3d40647
refine the testcases
imamnurby May 7, 2024
f4d3de0
refine testcases
imamnurby May 7, 2024
25062ec
rename files
imamnurby May 7, 2024
60a6070
cleanup files
imamnurby May 7, 2024
a076144
update script
imamnurby May 7, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 0 additions & 74 deletions data/raw/f_1000_zhihan.py

This file was deleted.

112 changes: 112 additions & 0 deletions data/raw/f_1000_zhihan_refined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import itertools
from random import shuffle

def f_1000(numbers=list(range(1, 3))):
"""
Calculates the average of the sums of absolute differences between each pair of consecutive numbers
for all permutations of a given list. Each permutation is shuffled before calculating the differences.

Args:
- numbers (list): A list of numbers. Default is numbers from 1 to 10.

Returns:
float: The average of the sums of absolute differences for each shuffled permutation of the list.

Requirements:
- itertools
- random.shuffle

Example:
>>> result = f_1000([1, 2, 3])
>>> isinstance(result, float)
True
"""
permutations = list(itertools.permutations(numbers))
sum_diffs = 0

for perm in permutations:
perm = list(perm)
shuffle(perm)
diffs = [abs(perm[i] - perm[i+1]) for i in range(len(perm)-1)]
sum_diffs += sum(diffs)

avg_sum_diffs = sum_diffs / len(permutations)

return avg_sum_diffs

import unittest
from unittest.mock import patch
from random import seed, shuffle
import itertools

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

class TestCases(unittest.TestCase):
def test_default_numbers(self):
# Test with default number range (1 to 10) to check that the result is a positive float.
result = f_1000()
self.assertIsInstance(result, float)
self.assertGreater(result, 0)

def test_custom_list(self):
# Test with a custom list of small positive integers to ensure proper handling and positive result.
result = f_1000([1, 2, 3])
self.assertIsInstance(result, float)
self.assertGreater(result, 0)

def test_negative_numbers(self):
# Test with negative numbers to verify the function handles and returns a positive result.
result = f_1000([-3, -2, -1])
self.assertIsInstance(result, float)
self.assertGreater(result, 0)

def test_single_element(self):
# Test with a single element list to confirm the return is zero since no pairs exist.
result = f_1000([5])
self.assertIsInstance(result, float)
self.assertEqual(result, 0)

def test_empty_list(self):
# Test with an empty list to ensure the function handles it gracefully and returns zero.
result = f_1000([])
self.assertIsInstance(result, float)
self.assertEqual(result, 0)

def test_identical_elements(self):
# Test with a list of identical elements to confirm that differences are zero and the average is zero.
result = f_1000([2, 2, 2])
self.assertIsInstance(result, float)
self.assertEqual(result, 0)

def test_mixed_numbers(self):
# Test with a list of mixed positive and negative numbers to check correct average of differences.
result = f_1000([-10, 10, -5])
self.assertIsInstance(result, float)
self.assertGreater(result, 0)

def test_specific_value_with_seed(self):
# Set seed for reproducibility and check the computed value
with patch('random.shuffle', side_effect=lambda x: seed(42) or shuffle(x)):
result = f_1000([1, 2, 3])
self.assertAlmostEqual(result, 2.5, delta=0.5) # This expected value should be calculated beforehand

def test_large_list_with_seed(self):
# Set seed and test with a larger list for specific computed value
with patch('random.shuffle', side_effect=lambda x: seed(99) or shuffle(x)):
result = f_1000(list(range(1, 11)))
self.assertAlmostEqual(result, 33.0, delta=0.5) # This expected value should be calculated beforehand

def test_random_behavior(self):
# Test to ensure different seeds produce different outputs, demonstrating randomness
with patch('random.shuffle', side_effect=lambda x: seed(1) or shuffle(x)):
result1 = f_1000([1, 2, 3])
with patch('random.shuffle', side_effect=lambda x: seed(1) or shuffle(x)):
result2 = f_1000([1, 2, 4])
self.assertNotEqual(result1, result2)

if __name__ == "__main__":
run_tests()
78 changes: 0 additions & 78 deletions data/raw/f_1001_zhihan.py

This file was deleted.

74 changes: 74 additions & 0 deletions data/raw/f_1001_zhihan_refined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import collections
import random
import string

def f_1001(length=100):
"""
Generate a random string of the specified length composed of uppercase and lowercase letters,
and then count the occurrence of each character in this string.

Parameters:
length (int, optional): The number of characters in the generated string. Default is 100.

Returns:
dict: A dictionary where each key is a character from the generated string and the value
is the count of how many times that character appears in the string.

Requirements:
- collections
- random
- string

Raises:
ValueError if the length is a negative number

Example:
>>> import random
>>> random.seed(42) # Ensures reproducibility for demonstration
>>> f_1001(10)
{'h': 1, 'B': 2, 'O': 1, 'L': 1, 'm': 1, 'j': 1, 'u': 1, 'E': 1, 'V': 1}
"""
if length < 0:
raise ValueError
random_string = ''.join(random.choices(string.ascii_uppercase + string.ascii_lowercase, k=length))
char_counts = collections.Counter(random_string)
return dict(char_counts)

import unittest
import string

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

class TestCases(unittest.TestCase):
def setUp(self):
# Prepare valid characters and set a random seed for reproducibility
self.valid_chars = string.ascii_uppercase + string.ascii_lowercase
random.seed(42) # Ensuring reproducibility for tests

def test_generated_string_properties(self):
# Consolidated test for different lengths to check structure and correctness
test_lengths = [10, 50, 100, 150, 5]
for length in test_lengths:
with self.subTest(length=length):
result = f_1001(length)
self.assertTrue(len(result) <= length, "Length of result should be <= requested string length")
self.assertEqual(sum(result.values()), length, f"Total counts should sum to {length}")
self.assertTrue(all(char in self.valid_chars for char in result), "All characters should be valid letters")

def test_zero_length(self):
# Test edge case where length is zero
result = f_1001(0)
self.assertEqual(len(result), 0, "Result should be empty for zero length")
self.assertEqual(sum(result.values()), 0, "Sum of counts should be zero for zero length")

def test_negative_length(self):
# Test handling of negative length input
with self.assertRaises(ValueError, msg="Negative length should raise an error"):
f_1001(-1)

if __name__ == "__main__":
run_tests()
Loading