Skip to content

Commit

Permalink
utils: add test for deserialize_bytes_tensor
Browse files Browse the repository at this point in the history
  • Loading branch information
stintel committed Feb 21, 2024
1 parent 73d1a63 commit 3f311c8
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,34 @@ pub(crate) fn deserialize_bytes_tensor(encoded_tensor: Vec<u8>) -> Result<Vec<St
}
Ok(strs)
}

#[cfg(test)]
mod tests {
use std::fs::File;
use std::io::Read;

use serde::Deserialize;

use super::deserialize_bytes_tensor;

#[derive(Deserialize)]
struct UtilsTestData {
input: Vec<u8>,
output: Vec<String>,
}

#[test]
fn test_deserialize_bytes_tensor() {
let mut test_data = String::new();

File::open("tests/utils.deserialize_bytes_tensor")
.unwrap()
.read_to_string(&mut test_data)
.unwrap();
let test_data: UtilsTestData = serde_json::from_str(&test_data).unwrap();

let test_result = deserialize_bytes_tensor(test_data.input).unwrap();

assert_eq!(test_result, test_data.output);
}
}
211 changes: 211 additions & 0 deletions tests/utils.deserialize_bytes_tensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
{
"input": [
200,
0,
0,
0,
72,
101,
108,
108,
111,
33,
32,
72,
111,
119,
32,
99,
97,
110,
32,
73,
32,
104,
101,
108,
112,
32,
121,
111,
117,
32,
116,
111,
100,
97,
121,
63,
32,
73,
115,
32,
116,
104,
101,
114,
101,
32,
97,
32,
115,
112,
101,
99,
105,
102,
105,
99,
32,
113,
117,
101,
115,
116,
105,
111,
110,
32,
111,
114,
32,
116,
111,
112,
105,
99,
32,
121,
111,
117,
39,
100,
32,
108,
105,
107,
101,
32,
116,
111,
32,
100,
105,
115,
99,
117,
115,
115,
63,
32,
73,
39,
109,
32,
104,
101,
114,
101,
32,
116,
111,
32,
112,
114,
111,
118,
105,
100,
101,
32,
105,
110,
102,
111,
114,
109,
97,
116,
105,
111,
110,
32,
97,
110,
100,
32,
97,
110,
115,
119,
101,
114,
32,
97,
110,
121,
32,
113,
117,
101,
115,
116,
105,
111,
110,
115,
32,
121,
111,
117,
32,
109,
105,
103,
104,
116,
32,
104,
97,
118,
101,
46,
32,
76,
101,
116,
32,
109,
101,
32,
107,
110,
111,
119,
32,
104,
111,
119,
32,
73,
32,
99,
97,
110,
32,
97,
115,
115,
105,
115,
116,
32,
121,
111,
117,
46
],
"output": [
"Hello! How can I help you today? Is there a specific question or topic you'd like to discuss? I'm here to provide information and answer any questions you might have. Let me know how I can assist you."
]
}

0 comments on commit 3f311c8

Please sign in to comment.