From 424f0251d6838c4c3563a64cc6516f552373f955 Mon Sep 17 00:00:00 2001
From: ammar68 <ammaa@stud.ntnu.no>
Date: Sun, 20 Oct 2024 13:38:28 +0200
Subject: [PATCH] add prefix check for isolation prompts

---
 llama/ollama-implementation/ollama_test.go | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/llama/ollama-implementation/ollama_test.go b/llama/ollama-implementation/ollama_test.go
index fcf920f..1ff5f01 100644
--- a/llama/ollama-implementation/ollama_test.go
+++ b/llama/ollama-implementation/ollama_test.go
@@ -75,7 +75,6 @@ func TestGetOllamaResponse(t *testing.T) {
 }
 
 // Test for prompts.
-
 var promptTestCases = []struct {
 	name          string
 	prompt        string
@@ -91,24 +90,22 @@ var promptTestCases = []struct {
 	{"Reverse the string rust.", "Reverse the string 'ammar'", extraction.RustPrompt, []string{"```rust", "```"}},
 }
 
+// Test function to verify the prefix and suffix of responses from GetOllamaResponse
 func TestGetOllamaResponsePrompts(t *testing.T) {
 	for _, tc := range promptTestCases {
 		t.Run(tc.name, func(t *testing.T) {
+			// Call the function to get the response
 			response, _, _ := GetOllamaResponse(tc.prompt+tc.suffixStr, []int{})
-			var prefix string
-			if tc.shouldContain[0] == "```go" {
-				prefix = response[0:5]
-				if prefix != tc.shouldContain[0] {
-					t.Errorf("Test faild expected %v got %v", tc.shouldContain[0], response[0:5])
+
+			// Check if the response starts with the expected prefix
+			if strings.HasPrefix(response, tc.shouldContain[0]) {
+				// Check if the response ends with "```"
+				if !strings.HasSuffix(response, "```") {
+					t.Errorf("Test %s failed: expected response to end with ```; got %q", tc.name, response)
 				}
 			} else {
-				prefix = response[0:7]
-				if prefix != tc.shouldContain[1] {
-					t.Errorf("Test faild expected %v got %v", tc.shouldContain[0], response[0:7])
-				}
+				t.Errorf("Test %s failed: expected response to start with %q; got %q", tc.name, tc.shouldContain[0], response)
 			}
 		})
-
 	}
-
 }
-- 
GitLab