forked from Mansafreo/PIE-Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_array_variables.pie
More file actions
75 lines (61 loc) · 1.91 KB
/
Copy pathtest_array_variables.pie
File metadata and controls
75 lines (61 loc) · 1.91 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
// Comprehensive test for array methods with variables
// Different variable types
int target_num = 42;
string target_name = "Bob";
char target_grade = 'B';
float target_score = 85.5;
// Arrays
int numbers[] = [10, 20, 42, 30];
string names[] = ["Alice", "Bob", "Charlie"];
char grades[] = ['A', 'B', 'C'];
float scores[] = [78.5, 85.5, 92.0];
// Test arr_contains with variables
output("Testing arr_contains with variables:", string);
if(arr_contains(numbers, target_num)){
output("Found target number!", string);
}
if(arr_contains(names, target_name)){
output("Found target name!", string);
}
if(arr_contains(grades, target_grade)){
output("Found target grade!", string);
}
if(arr_contains(scores, target_score)){
output("Found target score!", string);
}
// Test arr_indexof with variables
output("Testing arr_indexof with variables:", string);
int num_index = arr_indexof(numbers, target_num);
output("Target number index:", string);
output(num_index, int);
int name_index = arr_indexof(names, target_name);
output("Target name index:", string);
output(name_index, int);
int grade_index = arr_indexof(grades, target_grade);
output("Target grade index:", string);
output(grade_index, int);
int score_index = arr_indexof(scores, target_score);
output("Target score index:", string);
output(score_index, int);
// Test arr_push with variables
string new_name = "David";
int new_number = 50;
char new_grade = 'D';
float new_score = 67.0;
arr_push(names, new_name);
arr_push(numbers, new_number);
arr_push(grades, new_grade);
arr_push(scores, new_score);
output("After pushing variables:", string);
output("Names:", string);
output(names, array);
output("Numbers:", string);
output(numbers, array);
output("Grades:", string);
output(grades, array);
output("Scores:", string);
output(scores, array);
//test arr_pop
float popped=arr_pop(scores); //should remove last value and return it
output(popped,float,1);
output(scores,array);