Skip to content

Commit c966d96

Browse files
authored
Merge pull request #25 from Arend-Jan/24-adding-better-code-coverage-for-clientrs
adding more test
2 parents 1775a24 + ec2229f commit c966d96

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/client.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,4 +237,32 @@ mod tests {
237237
let result = client.chat(input).await;
238238
assert!(result.is_err());
239239
}
240+
241+
#[test]
242+
fn test_usage_struct() {
243+
let usage = Usage {
244+
prompt_tokens: 10,
245+
completion_tokens: 20,
246+
total_tokens: 30,
247+
};
248+
249+
assert_eq!(usage.prompt_tokens, 10);
250+
assert_eq!(usage.completion_tokens, 20);
251+
assert_eq!(usage.total_tokens, 30);
252+
}
253+
254+
#[test]
255+
fn test_choice_struct() {
256+
let choice = Choice {
257+
message: Message {
258+
role: Role::Assistant,
259+
content: "Sample response".to_string(),
260+
},
261+
finish_reason: "stop".to_string(),
262+
};
263+
264+
assert_eq!(choice.message.role, Role::Assistant);
265+
assert_eq!(choice.message.content, "Sample response");
266+
assert_eq!(choice.finish_reason, "stop");
267+
}
240268
}

src/models.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,29 @@ mod tests {
149149
let deserialized_model: Model = serde_json::from_str(model_json).unwrap();
150150
assert_eq!(deserialized_model, Model::Gpt_4);
151151
}
152+
153+
#[test]
154+
fn test_logit_bias_struct() {
155+
let mut biases = HashMap::new();
156+
biases.insert(42, 2.5);
157+
biases.insert(123, -1.3);
158+
159+
let logit_bias = LogitBias { biases };
160+
161+
assert_eq!(
162+
logit_bias.biases.get(&42),
163+
Some(&2.5),
164+
"Bias for token 42 should be 2.5"
165+
);
166+
assert_eq!(
167+
logit_bias.biases.get(&123),
168+
Some(&-1.3),
169+
"Bias for token 123 should be -1.3"
170+
);
171+
assert_eq!(
172+
logit_bias.biases.get(&999),
173+
None,
174+
"Bias for token 999 should not be set"
175+
);
176+
}
152177
}

0 commit comments

Comments
 (0)