Skip to content

Commit 9c193fc

Browse files
committed
Add another complex program test
1 parent b92e91c commit 9c193fc

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

tests/program.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,73 @@ func testComplexProgram3Success(t *testing.T, transpilerFunc transpilerFunc) {
312312
require.Equal(t, "Summary 1: OK: Math = 30 Success: 1\nSummary 2: FAIL: Science = 0 Success: 0\nLabels valid: 1 Message: all labels valid\nLabel 0 = Score_1\nLabel 1 = Score_2\nReportCard 1: OK: English = 15 Error: \nReportCard 2: FAIL: History = 0 Error: some scores were non-positive\nReportCard 3: Error: inactive user", output)
313313
})
314314
}
315+
316+
func testComplexProgram4Success(t *testing.T, transpilerFunc transpilerFunc) {
317+
transpilerFunc(t, `
318+
// Helper: Get element index for 2D logical position (row-major)
319+
func idx(row int, col int, cols int) int {
320+
return row*cols + col
321+
}
322+
323+
// Step 1: Generate scores as 1D slice representing 2D matrix
324+
func generateScores(students int, subjects int) []int {
325+
total := students * subjects
326+
scores := []int{}
327+
for i := 0; i < total; i++ {
328+
scores[i] = 0 // fill with zeros initially
329+
}
330+
331+
for r := 0; r < students; r++ {
332+
for c := 0; c < subjects; c++ {
333+
// Example scoring logic
334+
score := (r + 1) * (c + 2)
335+
scores[idx(r, c, subjects)] = score
336+
}
337+
}
338+
return scores
339+
}
340+
341+
// Step 2: Label a single student’s scores from 1D slice + indexing
342+
func labelStudentScores(scores []int, student int, subjects int) []string {
343+
labels := []string{}
344+
for i := 0; i < subjects; i++ {
345+
labels[len(labels)] = "Student" + itoa(student+1) + "_Sub" + itoa(i+1) + "=" + itoa(scores[idx(student, i, subjects)])
346+
}
347+
return labels
348+
}
349+
350+
// Step 3: Summarize student's labeled scores
351+
func summarizeStudent(labels []string) string {
352+
count := 0
353+
last := ""
354+
for i, l := range labels {
355+
count = i + 1
356+
last = l
357+
}
358+
return "Count=" + itoa(count) + ", Last=" + last
359+
}
360+
361+
// Step 4: Evaluate classroom by iterating students
362+
func evaluateClassroom(scores []int, students int, subjects int) []string {
363+
summaries := []string{}
364+
for s := 0; s < students; s++ {
365+
labels := labelStudentScores(scores, s, subjects)
366+
summary := summarizeStudent(labels)
367+
summaries[len(summaries)] = summary
368+
}
369+
return summaries
370+
}
371+
372+
students := 3
373+
subjects := 4
374+
scores := generateScores(students, subjects)
375+
summaries := evaluateClassroom(scores, students, subjects)
376+
377+
for i := 0; i < len(summaries); i++ {
378+
print("Student", itoa(i+1)+":", summaries[i])
379+
}
380+
`, func(output string, err error) {
381+
require.Nil(t, err)
382+
require.Equal(t, "Student 1: Count=4, Last=Student1_Sub4=5\nStudent 2: Count=4, Last=Student2_Sub4=10\nStudent 3: Count=4, Last=Student3_Sub4=15", output)
383+
})
384+
}

tests/program_linux_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ func TestComplexProgram2Success(t *testing.T) {
1515
func TestComplexProgram3Success(t *testing.T) {
1616
testComplexProgram3Success(t, transpileBash)
1717
}
18+
19+
func TestComplexProgram4Success(t *testing.T) {
20+
testComplexProgram4Success(t, transpileBash)
21+
}

tests/program_windows_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ func TestComplexProgram2Success(t *testing.T) {
1515
func TestComplexProgram3Success(t *testing.T) {
1616
testComplexProgram3Success(t, transpileBatch)
1717
}
18+
19+
func TestComplexProgram4Success(t *testing.T) {
20+
testComplexProgram4Success(t, transpileBatch)
21+
}

0 commit comments

Comments
 (0)