Skip to content

Commit

Permalink
Adding test cases for StringParser
Browse files Browse the repository at this point in the history
  • Loading branch information
hemantDwivedi committed Sep 14, 2023
1 parent 445d881 commit 1e85894
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.edgechain.parser;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
Expand All @@ -11,6 +8,8 @@

import com.edgechain.lib.openai.parser.StringParser;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
public class StringParserTest {

Expand Down Expand Up @@ -99,4 +98,36 @@ public void StringParser_GetFinalAnswer_ReturnsExpectedValue() {
assertNotNull(finalAnswer);
assertEquals("Final Answer", finalAnswer);
}

@Test
@DisplayName("Test String parser with empty input")
public void StringParser_EmptyInput_ReturnExpectedValue(){
String input = "";
assertThrows(Exception.class, () -> new StringParser(input));
}

@Test
@DisplayName("Test string parser with multiple thoughts, actions, and observations")
public void StringParser_MultipleContents_ReturnsExpectedValues() {
String input =
"Thought 1: Lorem ipsum\n"
+ "Action 1: [Search: Content for action 1]\n"
+ "Observation 1: Some observation\n"
+ "Thought 2: Dolor sit amet\n"
+ "Action 2: [Search: Content for action 2]\n"
+ "Observation 2: Another observation"
+ "Thought 3: Dolor sit amet\n"
+ "Action 3: [Search: Content for action 2]\n"
+ "Observation 3: Another observation";

StringParser parser = new StringParser(input);

String[] thoughts = parser.getThoughts();
String[] actions = parser.getActions();
String[] observations = parser.getObservations();

assertEquals(3, thoughts.length);
assertEquals(3, actions.length);
assertEquals(3, observations.length);
}
}

0 comments on commit 1e85894

Please sign in to comment.