@@ -312,3 +312,73 @@ func testComplexProgram3Success(t *testing.T, transpilerFunc transpilerFunc) {
312312 require .Equal (t , "Summary 1: OK: Math = 30 Success: 1\n Summary 2: FAIL: Science = 0 Success: 0\n Labels valid: 1 Message: all labels valid\n Label 0 = Score_1\n Label 1 = Score_2\n ReportCard 1: OK: English = 15 Error: \n ReportCard 2: FAIL: History = 0 Error: some scores were non-positive\n ReportCard 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\n Student 2: Count=4, Last=Student2_Sub4=10\n Student 3: Count=4, Last=Student3_Sub4=15" , output )
383+ })
384+ }
0 commit comments