-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtests.py
More file actions
109 lines (76 loc) · 3 KB
/
tests.py
File metadata and controls
109 lines (76 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
from main import CSV_Utils_Py
import ctypes
def run_test1():
sample_data = [
['Name', 'Age', 'Score'],
['Radha', '23', '85'],
['Bob', '23', '90'],
['Radha', '25', '78']
]
test_file = 'sample.csv'
CSV_Utils_Py.write_csv(test_file, sample_data)
def run_test2():
df = CSV_Utils_Py("./ppl.csv")
df.display_csv()
# df.output_processed_csv("output_ppl.csv")
filtered_data = df.filter_rows('Job Title', lambda x: x == "Games developer")
print("Filtered Data:", filtered_data)
sorted_data = df.sort_csv('Phone', ascending=False)
print("Sorted Data:", sorted_data)
total_score = df.aggregate_column('Index', 'sum')
print("Total Score:", total_score)
palindrome_count = df.count_valid_palindromes()
print("Valid Palindromes Count:", palindrome_count)
# os.remove(test_file)
# data = pd.read_csv("python/ppl.csv")
# print(data.to_string())
def run_test3():
df = CSV_Utils_Py("./fruits.csv")
df.display_csv()
df.output_processed_csv("output_fruits.csv")
filtered_data = df.filter_rows('Price', lambda x: float(x) > 1.0, True)
print("Filtered Data:", filtered_data)
sorted_data = df.sort_csv('Date', ascending=False)
print("Sorted Data:", sorted_data)
total_score = df.aggregate_column('Price', 'sum')
print("Total price:", total_score)
palindrome_count = df.count_valid_palindromes()
print("Valid Palindromes Count:", palindrome_count)
def run_test4():
df = CSV_Utils_Py("./ppl.csv")
# replace all "First Name": Shelby to Radha
df.replace_all_vals("First Name", "Shelby", "Radha")
# removes duplicates from "Job" Column
df.remove_duplicates("Job Title")
# Converts all first names to uppercase
df.apply_func("First Name", lambda s: s.upper())
# Export data to JSON
json_data = df.export_json("ppl.json")
print(json_data)
# counts palindromes in the csv file
df.count_valid_palindromes()
# show the summary of the csv file after analysis
df.summerize()
def run_go_binding_test1():
# !TODO! not completed yet, was just playing around !!
library = ctypes.cdll.LoadLibrary('./go_bindings/library.so')
library.readCSV.restype = None
# Set return type for the function (since it returns an int)
library.countPalindromes.restype = ctypes.c_int
# Call the function with the CSV file path
csv_path = b"ppl.csv" # Provide the actual CSV file path
result = library.countPalindromes(csv_path)
library.readCSV(csv_path)
print("Valid Palindrome Count: ", result)
if __name__ == "__main__":
run_test1()
run_test2()
run_test3()
run_test4()
# run_go_binding_test1()
# fast_csv.CountValidPalindromes.argtypes = [ctypes.c_char_p]
# fast_csv.CountValidPalindromes.restype = ctypes.c_int
# count = fast_csv.CountValidPalindromes(b"ppl.csv")
# print(count)
# count = fast_csv.CountValidPalindromes(b"ppl.csv")
# print("Palindrome Count:", count)