diff --git a/tests/texampleTests.m b/tests/texampleTests.m index 90b05e7..79b0420 100644 --- a/tests/texampleTests.m +++ b/tests/texampleTests.m @@ -65,6 +65,47 @@ function testAnalyzeSentimentinTextUsingChatGPTinJSONMode(testCase) testCase.verifyWarning(@AnalyzeSentimentinTextUsingChatGPTinJSONMode,... "llms:warningJsonInstruction"); end + + function testCreateSimpleChatBot(testCase) + % set up a fake input command, returning canned user prompts + count = 0; + prompts = [ + "Hello, how much do you know about physics?" + "What is torque?" + "What is force?" + "What is motion?" + "What is time?" + "end" + "end" + "end" + ]; + function res = input_(varargin) + count = count + 1; + res = prompts(count); + end + input = @input_; %#ok + + % to avoid errors about a static workspace, let MATLAB know we + % want these variables to exist + wordLimit = []; %#ok + stopWord = []; %#ok + modelName = []; %#ok + chat = []; %#ok + messages = []; + totalWords = []; %#ok + messagesSizes = []; %#ok + query = []; %#ok + numWordsQuery = []; %#ok + text = []; %#ok + response = []; %#ok + numWordsResponse = []; %#ok + + % Run the example + CreateSimpleChatBot; + + testCase.verifyEqual(count,find(prompts=="end",1)); + testCase.verifySize(messages.Messages,[1 2*(count-1)]); + end end end