Skip to content

Commit

Permalink
Add story format test
Browse files Browse the repository at this point in the history
This test ensures we don't break backwards compatability with the existing JSON format.
  • Loading branch information
mdegans committed Jun 16, 2024
1 parent ffb96b9 commit a60da23
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/story.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ impl std::fmt::Display for Story {

#[cfg(test)]
mod tests {
use std::path::PathBuf;

use super::*;

#[test]
Expand All @@ -349,4 +351,26 @@ mod tests {
assert_eq!(Some(id as u8), story.get_author(author));
});
}

// This tests we don't break backwards compatibility with the old format.
#[test]
fn test_story_deserialize() {
let json_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("test")
.join("data")
.join("sharks.0.0.3.json");

assert!(json_path.exists(), "Test data not found: {:?}", json_path);

let json = std::fs::read_to_string(json_path).unwrap();
let story: Story = serde_json::from_str(&json).unwrap();
assert_eq!(story.title, "Electrocuting Sharks");
assert_eq!(story.root.count(), 23);
let mut len = 0;
for node in story.root.iter_depth_first() {
len += node.text.len();
}
assert_eq!(len, 7453);
// We're not checking the format or display because they may change.
}
}
1 change: 1 addition & 0 deletions test/data/sharks.0.0.3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"active_path":[0,0,0,1,1],"title":"Electrocuting Sharks","author_to_id":{"llama-3-70b.Q6K.lot.gguf":1,"":0,"Llama-3-70b-Arimas-story-RP-V1.5.i1-Q5_K_M.gguf":2},"id_to_author":["","llama-3-70b.Q6K.lot.gguf","Llama-3-70b-Arimas-story-RP-V1.5.i1-Q5_K_M.gguf"],"root":{"author_id":0,"text":"Below is an excerpt from Donald Trump's latest speech, quoted by the Washington Post:\n\n“I say, ‘What would happen if the boat sank from its weight, and you’re in the boat, and you have this tremendously powerful battery, and the battery’s now underwater, and there’s a shark that’s approximately 10 yards over there?’","pieces":[{"end":331}],"children":[{"author_id":0,"text":"“By the way, a lot of shark attacks lately, do you notice that? Lot of sharks. I watched some guys justifying it today: ‘Well they weren’t really that angry, they bit off the young lady’s leg because of the fact that they were not hungry but they misunderstood who she was.’ These people are crazy. He said, ‘There’s no problem with sharks, they just didn’t really understand a young woman swimming.’ No, really got decimated, and other people, too, a lot of shark attacks.","pieces":[{"end":491}],"children":[{"author_id":0,"text":"“So I said, ‘There’s a shark 10 yards away from the boat, 10 yards, or here. Do I get electrocuted if the boat is sinking, water goes over the battery, the boat is sinking? Do I stay on top of the boat and get electrocuted, or do I jump over by the shark and not get electrocuted?’ Because I will tell you, he didn’t know the answer.","pieces":[{"end":343}],"children":[{"author_id":0,"text":"“He said, ‘You know, nobody’s ever asked me that question.’ I said, ‘I think it’s a good question. I think there’s a lot of electric current coming through that water.’ But you know what I’d do if there was a shark or you get electrocuted? I’ll take electrocution every single time. I’m not getting near the shark. So we’re going to end that, we’re going to end it for boats, we’re going to end it for trucks.”","pieces":[{"end":440}],"children":[{"author_id":0,"text":"The WaPo article goes on to explain that this speech was in the context of a discussion of the potential dangers of electric vehicles. It seems that the context is that some sort of electric vehicle (presumably a boat) is sinking and has a \"tremendously powerful battery\" on board, and the question is whether the water around it could electrocute someone in the water. But what I'd like to know is... what's going on with this speech? It seems like a non sequitur, and the shark reference is just bizarre. Is this just another example of Trump's stream-of-consciousness rambling, or is there something deeper going on here?","pieces":[{"end":3},{"end":6},{"end":8},{"end":16},{"end":21},{"end":24},{"end":27},{"end":35},{"end":40},{"end":45},{"end":52},{"end":56},{"end":59},{"end":63},{"end":71},{"end":74},{"end":76},{"end":87},{"end":90},{"end":94},{"end":104},{"end":112},{"end":115},{"end":124},{"end":133},{"end":134},{"end":137},{"end":143},{"end":148},{"end":152},{"end":160},{"end":163},{"end":168},{"end":173},{"end":178},{"end":181},{"end":190},{"end":198},{"end":200},{"end":204},{"end":210},{"end":212},{"end":217},{"end":218},{"end":221},{"end":229},{"end":233},{"end":237},{"end":239},{"end":241},{"end":242},{"end":245},{"end":248},{"end":253},{"end":262},{"end":270},{"end":271},{"end":274},{"end":280},{"end":281},{"end":285},{"end":289},{"end":298},{"end":301},{"end":309},{"end":313},{"end":319},{"end":326},{"end":329},{"end":335},{"end":343},{"end":344},{"end":347},{"end":355},{"end":358},{"end":362},{"end":368},{"end":369},{"end":373},{"end":378},{"end":380},{"end":382},{"end":387},{"end":390},{"end":395},{"end":398},{"end":401},{"end":406},{"end":408},{"end":414},{"end":417},{"end":422},{"end":427},{"end":434},{"end":435},{"end":438},{"end":444},{"end":449},{"end":451},{"end":455},{"end":460},{"end":464},{"end":465},{"end":469},{"end":473},{"end":479},{"end":489},{"end":492},{"end":497},{"end":505},{"end":506},{"end":509},{"end":514},{"end":519},{"end":527},{"end":535},{"end":538},{"end":544},{"end":546},{"end":553},{"end":556},{"end":566},{"end":570},{"end":574},{"end":579},{"end":580},{"end":583},{"end":586},{"end":592},{"end":602},{"end":609},{"end":615},{"end":618},{"end":623},{"end":624}],"children":[],"meta":{"id":220579172014656594368943409455624988784,"pos":{"x":1392.5,"y":718.0},"size":{"x":300.0,"y":272.682}}},{"author_id":0,"text":"—Donald Trump, speaking at a campaign rally in Pennsylvania on Friday about electric vehicles and a hypothetical scenario involving a shark attack.","pieces":[{"end":3},{"end":9},{"end":15},{"end":16},{"end":25},{"end":28},{"end":30},{"end":39},{"end":45},{"end":48},{"end":61},{"end":64},{"end":71},{"end":77},{"end":86},{"end":95},{"end":99},{"end":101},{"end":114},{"end":123},{"end":133},{"end":135},{"end":141},{"end":148},{"end":149}],"children":[{"author_id":0,"text":"He went on to say that the issue with electric vehicles is that they can be dangerous, and that he would prioritize gasoline-powered cars.\n\nMy question: Can a person get electrocuted by jumping out of a sinking electric car or boat into water, if the battery is submerged?","pieces":[{"end":2},{"end":7},{"end":10},{"end":13},{"end":17},{"end":22},{"end":26},{"end":32},{"end":37},{"end":46},{"end":55},{"end":58},{"end":63},{"end":68},{"end":72},{"end":75},{"end":85},{"end":86},{"end":90},{"end":95},{"end":98},{"end":104},{"end":115},{"end":124},{"end":132},{"end":137},{"end":140},{"end":142},{"end":151},{"end":152},{"end":156},{"end":158},{"end":165},{"end":169},{"end":177},{"end":178},{"end":182},{"end":185},{"end":193},{"end":197},{"end":200},{"end":202},{"end":210},{"end":219},{"end":223},{"end":226},{"end":231},{"end":236},{"end":242},{"end":243},{"end":246},{"end":250},{"end":258},{"end":261},{"end":271},{"end":272}],"children":[],"meta":{"id":178733980233826431958773844894276749180,"pos":{"x":1756.0,"y":153.5},"size":{"x":300.0,"y":106.13202}}},{"author_id":0,"text":"What do you think he meant by this passage? Was it coherent? Did he make a valid point? Did he successfully communicate a clear idea?\n\nIn my opinion, the passage is not coherent and does not make a valid point. The scenario he presents is nonsensical and unrelated to the topic of electric vehicles, which he claims to be discussing. The hypothetical situation involving a sinking boat, a shark, and electrocution does not have any logical connection to electric vehicles or any other topic relevant to a political campaign.","pieces":[{"end":524}],"children":[],"meta":{"id":185061847881279834459430474733641454201,"pos":{"x":1750.5,"y":564.5},"size":{"x":300.0,"y":243.682}}}],"meta":{"id":261321866107945056372042006650495336570,"pos":{"x":1751.5,"y":392.5},"size":{"x":300.0,"y":127.68201}}}],"meta":{"id":84072695734281458027696198987514272834,"pos":{"x":1394.0,"y":478.0},"size":{"x":300.0,"y":200.182}}},{"author_id":0,"text":"“Now, in the old days, they would have said, ‘Jump in the water, sir, and swim away from the boat, and you’ll be fine, and you’ll live, and the shark will be fine.’","pieces":[{"end":174}],"children":[{"author_id":0,"text":"“They didn’t know what to do. I was telling them, and I know what I was doing, I was just asking a question, and I was getting a lot of fake news saying, ‘He doesn’t know the answer to that question, he’s not a sailor.","pieces":[{"end":228}],"children":[],"meta":{"id":138014951840210925434142278332121875656,"pos":{"x":1050.5,"y":64.5},"size":{"x":300.0,"y":142.182}}}],"meta":{"id":4349755014894800583497440171448704287,"pos":{"x":1052.1412,"y":258.65564},"size":{"x":300.0,"y":127.68201}}},{"author_id":0,"text":"“’Cause if the boat is sinking, and it’s underwater, you know, the boat’s going down, you have a tremendous battery, you’re in the water, and there’s a shark 10 yards away, do you stay on the boat and get electrocuted, or do you jump in the water and take a chance with the shark? That’s what I did. I did that. And you know what? I jumped in the water. And I didn’t get electrocuted, and I didn’t get eaten by the shark. That’s what I did. And that’s the way it is, folks. That’s the way it is. You gotta make tough decisions.","pieces":[{"end":551}],"children":[{"author_id":0,"text":"“So I’m telling you, these guys don’t know what they’re doing. They’re not gonna get us out of this mess. We need a leader who’s gonna make tough decisions, who’s gonna make the right decisions, and we’re gonna win, we’re gonna win so bigly, believe me.”","pieces":[{"end":274}],"children":[],"meta":{"id":166826830221690939010797189112137652860,"pos":{"x":1049.0,"y":977.0},"size":{"x":300.0,"y":156.682}}}],"meta":{"id":56080440255840095444239726341678292598,"pos":{"x":1070.0,"y":698.5},"size":{"x":300.0,"y":243.682}}},{"author_id":0,"text":"“And the other guy said, ‘Sir, that’s a good question.’","pieces":[{"end":6},{"end":10},{"end":16},{"end":20},{"end":25},{"end":26},{"end":30},{"end":33},{"end":34},{"end":39},{"end":43},{"end":45},{"end":50},{"end":59},{"end":63}],"children":[{"author_id":0,"text":"“I don’t know, do I jump into the water and take my chances with the shark, or do I stay on the boat and take my chances with the electrocution? And then I started thinking, you know, that’s a good question. But I think I would jump. Because, you know, I don’t want to be electrocuted.","pieces":[{"end":293}],"children":[],"meta":{"id":315663024563385100590431660839977228436,"pos":{"x":1402.0,"y":98.0},"size":{"x":300.0,"y":156.682}}}],"meta":{"id":125597921311642326827690916740500191533,"pos":{"x":1395.0,"y":307.0},"size":{"x":300.0,"y":127.13202}}}],"meta":{"id":215777081240780536484244911161207305799,"pos":{"x":1053.3116,"y":450.03455},"size":{"x":300.0,"y":171.182}}},{"author_id":0,"text":"“But you have a tremendously powerful battery, and you have this boat, and it’s underwater, and you have a shark, and the shark comes over and starts eating the boat. You know what happens? The boat’s gone. The shark’s gone. The battery’s gone. And you’re underwater, and you have to find it. You can’t find it. That’s the problem. That’s a big problem. Nobody thought of that.","pieces":[{"end":395}],"children":[{"author_id":0,"text":"“Nobody thought of that. They didn’t think of that. That’s a big problem. So you have to have the right technology, and you have to have the right people. And we don’t have the right people, believe me.","pieces":[{"end":210}],"children":[{"author_id":0,"text":"“’We don’t have the right people. We don’t have the right technology. We don’t have the right anything. We don’t have the right boats. We don’t have the right — the right boats. We don’t have the right — and the Navy is the same thing. We don’t have the right anything. And that’s why we’re gonna win so bigly, folks. That’s why we’re gonna win so bigly.“","pieces":[{"end":387}],"children":[],"meta":{"id":331737750561424116708276174800428540806,"pos":{"x":716.959,"y":954.38074},"size":{"x":300.0,"y":185.682}}}],"meta":{"id":151870826466786824778033764047083149447,"pos":{"x":720.4653,"y":749.4524},"size":{"x":300.0,"y":142.182}}}],"meta":{"id":29789688831491586864348335525710801333,"pos":{"x":706.5,"y":501.0},"size":{"x":300.0,"y":185.682}}},{"author_id":0,"text":"“’Cause what they do is they have an electromagnetic field and the electromagnetic field is so strong, it’s like a magnet, and it draws in sharks, okay? So you have this tremendous electromagnetic field, and the shark goes after the boat.","pieces":[{"end":244}],"children":[],"meta":{"id":21176348914297568424942012567688263110,"pos":{"x":690.5,"y":24.0},"size":{"x":300.0,"y":156.682}}}],"meta":{"id":272352760680375646185086108399668717820,"pos":{"x":689.7145,"y":222.77159},"size":{"x":300.0,"y":214.682}}},{"author_id":0,"text":"“Would the shark go after the battery, or would the shark go after you? I don’t know, I don’t know. But I do know this: the shark is not going to go after the battery. The shark is going to go after you, because the shark is a winner. The shark is a killer. The shark is a tremendous killer. And the battery is just a battery. It’s not going to go after the battery.","pieces":[{"end":374}],"children":[{"author_id":0,"text":"“You know, it’s a tremendous problem, folks. Nobody talks about it. Nobody talks about it. But it’s a tremendous problem. Nobody talks about it. And I know more about batteries than any doctor, any expert, any expert, anybody. I know more about batteries than anybody.","pieces":[{"end":274}],"children":[{"author_id":0,"text":"“And I know more about wind than any expert, anybody. And the wind is a very deceiving thing.","pieces":[{"end":95}],"children":[{"author_id":0,"text":"“It looks like it’s a beautiful, beautiful day, the sun is out, it’s a beautiful day, and then, all of a sudden, the wind comes in and the wind is so powerful, and it’s like a hurricane. And the turbines, they start to spin, and they’re so slow, and they’re so weak, and they’re so fragile. And they’re so expensive. And they’re made in China.","pieces":[{"end":361}],"children":[{"author_id":0,"text":"“Nobody talks about it. And then you have the birds. And the birds are so beautiful. And they’re so — you know, they’re so wonderful. But they get killed by the turbines. And you see them, they get killed by the turbines. The turbines are so bad. And then you have the noise, and the rust, and the decay, and the environmental damage is incredible.","pieces":[{"end":356}],"children":[],"meta":{"id":47551886926963900107845191277249149548,"pos":{"x":372.1717,"y":1145.5623},"size":{"x":300.0,"y":185.68213}}}],"meta":{"id":167204203094649847689855494600572655563,"pos":{"x":344.0,"y":891.0},"size":{"x":300.0,"y":171.182}}}],"meta":{"id":12814074384962444918900944853237132868,"pos":{"x":374.5,"y":720.5},"size":{"x":300.0,"y":127.13202}}}],"meta":{"id":311443929092296185413063626301785682007,"pos":{"x":295.91168,"y":520.8321},"size":{"x":300.0,"y":135.682}}}],"meta":{"id":228035054633877904221956800878723154501,"pos":{"x":233.15456,"y":272.29642},"size":{"x":300.0,"y":185.682}}}],"meta":{"id":295846872296959487537911144636350112054,"pos":{"x":325.83688,"y":23.116682},"size":{"x":300.0,"y":185.682}}}}

0 comments on commit a60da23

Please sign in to comment.