Skip to content

Commit 73a835e

Browse files
committed
tests
1 parent 2777287 commit 73a835e

File tree

3 files changed

+87
-32
lines changed

3 files changed

+87
-32
lines changed

tests/ChatHistoryTest.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace NeuronAI\Tests;
4+
5+
use NeuronAI\AbstractChatHistory;
6+
use NeuronAI\InMemoryChatHistory;
7+
use NeuronAI\Messages\UserMessage;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class ChatHistoryTest extends TestCase
11+
{
12+
/**
13+
* Sets up the fixture, for example, open a network connection.
14+
* This method is called before a test is executed.
15+
*
16+
* @throws \Exception
17+
*/
18+
public function setUp(): void
19+
{
20+
}
21+
22+
public function testChatHistoryInstance()
23+
{
24+
$history = new InMemoryChatHistory();
25+
$this->assertInstanceOf(AbstractChatHistory::class, $history);
26+
}
27+
28+
public function testChatHistoryAddMessage()
29+
{
30+
$history = new InMemoryChatHistory();
31+
$history->addMessage(new UserMessage('Hello!'));
32+
$this->assertCount(1, $history->getMessages());
33+
$this->assertEquals(1, $history->count());
34+
}
35+
36+
public function testChatHistoryLastMessage()
37+
{
38+
$history = new InMemoryChatHistory();
39+
$history->addMessage(new UserMessage('Hello!'));
40+
$history->addMessage(new UserMessage('Hello2!'));
41+
$this->assertEquals('Hello2!', $history->getLastMessage()->getContent());
42+
}
43+
44+
public function testChatHistoryTruncateOldMessages()
45+
{
46+
$history = new InMemoryChatHistory();
47+
$history->addMessage(new UserMessage('Hello!'));
48+
$history->addMessage(new UserMessage('Hello2!'));
49+
$history->truncate(1);
50+
$this->assertEquals(1, $history->count());
51+
$this->assertEquals('Hello2!', $history->getLastMessage()->getContent());
52+
}
53+
54+
public function testChatHistoryClear()
55+
{
56+
$history = new InMemoryChatHistory();
57+
$history->addMessage(new UserMessage('Hello!'));
58+
$history->addMessage(new UserMessage('Hello2!'));
59+
$history->clear();
60+
$this->assertCount(0, $history->getMessages());
61+
$this->assertEquals(0, $history->count());
62+
}
63+
}

tests/NeuronAITest.php

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
namespace NeuronAI\Tests;
44

55

6-
use NeuronAI\AbstractChatHistory;
76
use NeuronAI\Agent;
8-
use NeuronAI\InMemoryChatHistory;
9-
use NeuronAI\Messages\UserMessage;
7+
use NeuronAI\RAG\RAG;
108
use NeuronAI\RAG\VectorStore\MemoryVectorStore;
11-
use NeuronAI\RAG\VectorStore\VectorStoreInterface;
129
use PHPUnit\Framework\TestCase;
1310

1411
class NeuronAITest extends TestCase
@@ -23,37 +20,12 @@ public function setUp(): void
2320
{
2421
}
2522

26-
public function testInstance()
23+
public function testAgentInstance()
2724
{
2825
$neuron = new Agent();
29-
$this->assertInstanceOf(Agent::class, $neuron);
3026
$this->assertInstanceOf(\SplSubject::class, $neuron);
31-
}
32-
33-
public function testChatHistory()
34-
{
35-
$history = new InMemoryChatHistory();
36-
$this->assertInstanceOf(AbstractChatHistory::class, $history);
37-
38-
$history->addMessage(new UserMessage('Hello!'));
39-
$this->assertCount(1, $history->getMessages());
40-
$this->assertEquals(1, $history->count());
41-
42-
$history->addMessage(new UserMessage('Hello2!'));
43-
$this->assertEquals('Hello2!', $history->getLastMessage()->getContent());
4427

45-
$history->truncate(1);
46-
$this->assertEquals(1, $history->count());
47-
$this->assertEquals('Hello2!', $history->getLastMessage()->getContent());
48-
49-
$history->clear();
50-
$this->assertCount(0, $history->getMessages());
51-
$this->assertEquals(0, $history->count());
52-
}
53-
54-
public function testVectorStore()
55-
{
56-
$store = new MemoryVectorStore();
57-
$this->assertInstanceOf(VectorStoreInterface::class, $store);
28+
$neuron = new RAG(new MemoryVectorStore());
29+
$this->assertInstanceOf(Agent::class, $neuron);
5830
}
5931
}

tests/VectorStoreTes.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace NeuronAI\Tests;
4+
5+
use NeuronAI\RAG\VectorStore\MemoryVectorStore;
6+
use NeuronAI\RAG\VectorStore\VectorStoreInterface;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class VectorStoreTes extends TestCase
10+
{
11+
protected function setUp(): void
12+
{
13+
}
14+
15+
public function testVectorStoreInstance()
16+
{
17+
$store = new MemoryVectorStore();
18+
$this->assertInstanceOf(VectorStoreInterface::class, $store);
19+
}
20+
}

0 commit comments

Comments
 (0)