advent-of-code-data 0.0.2

Advent of Code API for submitting answers and getting inputs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
use std::io::{BufRead, BufReader, BufWriter, Read, Write};

use serde::{Deserialize, Serialize};
use std::str::FromStr;
use thiserror::Error;

use crate::{Answer, Day, Part, Year};

pub const CORRECT_ANSWER_CHAR: char = '=';
pub const WRONG_ANSWER_CHAR: char = 'X';
pub const LOW_ANSWER_CHAR: char = '[';
pub const HIGH_ANSWER_CHAR: char = ']';

/// Stores puzzle input and answer data.
#[derive(Debug, PartialEq)]
pub struct Puzzle {
    pub day: Day,
    pub year: Year,
    pub input: String,
    pub part_one_answers: Answers,
    pub part_two_answers: Answers,
}

impl Puzzle {
    pub fn answers(&self, part: Part) -> &Answers {
        match part {
            Part::One => &self.part_one_answers,
            Part::Two => &self.part_two_answers,
        }
    }

    pub fn answers_mut(&mut self, part: Part) -> &mut Answers {
        match part {
            Part::One => &mut self.part_one_answers,
            Part::Two => &mut self.part_two_answers,
        }
    }
}

/// Represents the various outcomes of checking an answer against an answers
/// database.
#[derive(Clone, Debug, PartialEq)]
pub enum CheckResult {
    /// The answer is correct.
    Correct,
    /// The answer is incorrect.
    Wrong,
    /// The answer is too low and incorrect.
    TooLow,
    /// The answer is too high and incorrect.
    TooHigh,
}

/// Stores correct and incorrect answers for a puzzle, along with hints such as
/// "too large" and "too small".
#[derive(Debug, PartialEq)]
pub struct Answers {
    correct_answer: Option<Answer>,
    wrong_answers: Vec<Answer>,
    low_bounds: Option<i128>,
    high_bounds: Option<i128>,
}

impl Answers {
    /// Initialize new `Answers` object.
    pub fn new() -> Self {
        Answers {
            correct_answer: None,
            wrong_answers: Vec::new(),
            low_bounds: None,
            high_bounds: None,
        }
    }

    pub fn correct_answer_ref(&self) -> &Option<Answer> {
        &self.correct_answer
    }

    pub fn wrong_answers_ref(&self) -> &Vec<Answer> {
        &self.wrong_answers
    }

    pub fn low_bounds_ref(&self) -> &Option<i128> {
        &self.low_bounds
    }

    pub fn high_bounds_ref(&self) -> &Option<i128> {
        &self.high_bounds
    }

    /// Checks if this answer is correct or incorrect according to the information
    /// stored in this `Answers` database.
    ///
    /// `None` is returned when the supplied answer does not match any known
    /// incorrect values, and the database does not have a known correct value.
    /// When a `None` value is returned, the caller should submit the answer as
    /// a solution to the puzzle using the Advent of Code client. The caller
    /// should then update this object with the response depending on if the
    /// client say it was correct or incorrect.
    pub fn check(&self, answer: &Answer) -> Option<CheckResult> {
        // Check the answer against the optional low and high value boundaries.
        match (answer.to_i128(), &self.low_bounds, &self.high_bounds) {
            (Some(answer), Some(low), _) if answer <= *low => {
                return Some(CheckResult::TooLow);
            }
            (Some(answer), _, Some(high)) if answer >= *high => return Some(CheckResult::TooHigh),
            _ => {}
        };

        // Check if the answer is matches any known incorrect answers.
        for wrong_answer in &self.wrong_answers {
            if wrong_answer == answer {
                return Some(CheckResult::Wrong);
            }
        }

        // Now see if the answer matches the correct answer or return `None` if
        // the correct answer is not known.
        match &self.correct_answer {
            Some(correct) if correct == answer => Some(CheckResult::Correct),
            Some(_) => Some(CheckResult::Wrong),
            None => None,
        }
    }

    /// Adds an answer to the list of known wrong answers.
    pub fn add_wrong_answer(&mut self, answer: Answer) {
        // TODO: Verify that wrong answer is not the correct answer
        // TODO: Error if the wrong answer has a newline.
        if self.wrong_answers.iter().all(|x| x != &answer) {
            self.wrong_answers.push(answer);
        } else {
            tracing::warn!(
                "skipped adding duplicate wrong answer to answers cache: `{}`",
                answer
            );
        }
    }

    /// Sets this answer as the known correct answer.
    pub fn set_correct_answer(&mut self, answer: Answer) {
        // TODO: Verify that correct answer is not a wrong answer, hi or low.
        // TODO: Error if the right answer has a newline.
        self.correct_answer = Some(answer);
    }

    /// Sets a low boundary value in the cache.
    ///
    /// If the cache has an existing low boundary then the highest value will be
    /// used as the new high boundary.
    ///
    /// Any numeric answer passed to `Answers::check` will be returned as
    /// `CheckResult::TooLow` if it equals or is smaller than the low boundary.
    pub fn set_low_bounds(&mut self, answer: Answer) -> i128 {
        // TODO: Verify that low bounds is not a correct answer.
        // TODO: Verify that low bounds is not larger or equal to high bounds.
        // TODO: Remove panic and return Error if the answer is not an integer.
        let answer = answer.to_i128().expect("low bounds answer must be numeric");

        match &self.low_bounds {
            Some(low) if answer > *low => {
                self.low_bounds = Some(answer);
                answer
            }
            Some(low) => *low,
            None => {
                self.low_bounds = Some(answer);
                answer
            }
        }
    }

    /// Sets a high boundary value in the cache.
    ///
    /// If the cache has an existing high boundary then the lowest value will be
    /// used as the new high boundary.
    ///
    /// Any numeric answer passed to `Answers::check` will be returned as
    /// `CheckResult::TooHigh` if it equals or is larger than the high boundary.
    pub fn set_high_bounds(&mut self, answer: Answer) -> i128 {
        // TODO: Verify that high bounds is not a correct answer.
        // TODO: Verify that high bounds is not smaller or equal to low bounds.
        // TODO: Remove panic and return Error if the answer is not an integer.
        let answer = answer
            .to_i128()
            .expect("high bounds answer must be numeric");

        match &self.high_bounds {
            Some(high) if answer < *high => {
                self.high_bounds = Some(answer);
                answer
            }
            Some(high) => *high,
            None => {
                self.high_bounds = Some(answer);
                answer
            }
        }
    }

    pub fn serialize_to_string(&self) -> String {
        // TODO: Convert unwraps into Errors.
        let mut buf = BufWriter::new(Vec::new());
        self.serialize(&mut buf);

        String::from_utf8(buf.into_inner().unwrap()).unwrap()
    }

    pub fn serialize<W: Write>(&self, writer: &mut BufWriter<W>) {
        // TODO: Support newlines in answers.
        // TODO: Convert unwraps to Errors.

        // Sort wrong answers alphabetically to ensure stability with diffs
        // for version control.
        let mut wrong_answers: Vec<String> =
            self.wrong_answers.iter().map(|x| x.to_string()).collect();
        wrong_answers.sort();

        // Serialize all the answers to buffered writer.
        fn write_field<S: ToString, W: Write>(
            field: &Option<S>,
            prefix: char,
            writer: &mut BufWriter<W>,
        ) {
            if let Some(f) = field {
                let s = f.to_string();
                assert!(!s.contains('\n'));

                writeln!(writer, "{} {}", prefix, &s).unwrap();
            }
        }

        write_field(&self.correct_answer, CORRECT_ANSWER_CHAR, writer);
        write_field(&self.low_bounds, LOW_ANSWER_CHAR, writer);
        write_field(&self.high_bounds, HIGH_ANSWER_CHAR, writer);

        for wrong_answer in wrong_answers {
            write_field(&Some(wrong_answer), WRONG_ANSWER_CHAR, writer);
        }
    }

    pub fn deserialize_from_str(text: &str) -> Result<Self, AnswerDeserializationError> {
        // TODO: Write tests.
        let mut buf = BufReader::new(text.as_bytes());
        Self::deserialize(&mut buf)
    }

    pub fn deserialize<R: Read>(
        reader: &mut BufReader<R>,
    ) -> Result<Self, AnswerDeserializationError> {
        // TODO: Convert unwrap/expect into Errors
        // TODO: Write tests.
        let mut answers = Answers::new();

        // Each line in the input string is an entry in the answers database.
        // The first character indicates the type of answer, and the characters
        // following the space hold the answer value.
        for line in reader.lines() {
            let line = line.unwrap();
            let (ty, value) = line
                .split_once(' ')
                .ok_or_else(|| AnswerDeserializationError::UnknownLineFormat(line.clone()))?;

            match ty.chars().next().unwrap() {
                CORRECT_ANSWER_CHAR => {
                    answers.set_correct_answer(
                        Answer::from_str(value).expect("Answer::from_str does not return Err"),
                    );
                }
                WRONG_ANSWER_CHAR => {
                    answers.add_wrong_answer(
                        Answer::from_str(value).expect("Answer::from_str does not return Err"),
                    );
                }
                LOW_ANSWER_CHAR => {
                    let low = value.parse::<i128>().map_err(|_| {
                        AnswerDeserializationError::LowBoundRequiresInt(value.to_string())
                    })?;
                    answers.set_low_bounds(Answer::Int(low));
                }
                HIGH_ANSWER_CHAR => {
                    let high = value.parse::<i128>().map_err(|_| {
                        AnswerDeserializationError::HighBoundRequiresInt(value.to_string())
                    })?;
                    answers.set_high_bounds(Answer::Int(high));
                }
                c => {
                    return Err(AnswerDeserializationError::UnknownAnswerType(c));
                }
            }
        }

        Ok(answers)
    }
}

impl Default for Answers {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(Debug, Error)]
pub enum AnswerDeserializationError {
    #[error(
        "expected type char followed by a space followed by the answer value, but got `{}`", .0
    )]
    UnknownLineFormat(String),
    #[error(
        "unknown answer type char `{}` when deserializing (expected `{}`, `{}`, `{}`, or `{}`)",
        .0,
        CORRECT_ANSWER_CHAR,
        WRONG_ANSWER_CHAR,
        LOW_ANSWER_CHAR,
        HIGH_ANSWER_CHAR
    )]
    UnknownAnswerType(char),
    #[error("the low bound answer `{}` must be parsable as an i128 integer", .0)]
    LowBoundRequiresInt(String),
    #[error("the high bound answer `{}` must be parsable as an i128 integer", .0)]
    HighBoundRequiresInt(String),
}

#[derive(Serialize, Deserialize)]
pub struct Session {
    pub session_id: String,
    pub submit_wait_until: Option<chrono::DateTime<chrono::Utc>>,
}

impl Session {
    pub fn new<S: Into<String>>(session_id: S) -> Self {
        Self {
            session_id: session_id.into(),
            submit_wait_until: None,
        }
    }
}

#[cfg(test)]
mod tests {

    use super::*;

    #[test]
    fn add_wrong_answers() {
        let mut answers = Answers::new();

        answers.add_wrong_answer(Answer::from_str("hello world").unwrap());
        answers.add_wrong_answer(Answer::from_str("foobar").unwrap());
        answers.add_wrong_answer(Answer::Int(42));

        assert_eq!(
            answers.wrong_answers_ref(),
            &vec![
                Answer::String("hello world".to_string()),
                Answer::String("foobar".to_string()),
                Answer::Int(42)
            ]
        )
    }

    #[test]
    fn correct_answer_when_checking() {
        let mut answers = Answers::new();

        answers.set_correct_answer(Answer::from_str("hello").unwrap());
        answers.add_wrong_answer(Answer::from_str("abc").unwrap());
        answers.add_wrong_answer(Answer::from_str("stop").unwrap());

        assert_eq!(
            answers.check(&Answer::from_str("hello").unwrap()),
            Some(CheckResult::Correct)
        );
    }

    #[test]
    fn wrong_answer_when_checking() {
        let mut answers = Answers::new();

        answers.set_correct_answer(Answer::from_str("hello").unwrap());
        answers.add_wrong_answer(Answer::from_str("abc").unwrap());
        answers.add_wrong_answer(Answer::from_str("stop").unwrap());

        assert_eq!(
            answers.check(&Answer::from_str("abc").unwrap()),
            Some(CheckResult::Wrong)
        );
        assert_eq!(
            answers.check(&Answer::from_str("stop").unwrap()),
            Some(CheckResult::Wrong)
        );
    }

    #[test]
    fn set_lower_high_boundary_replaces_prev() {
        let mut answers = Answers::new();
        assert_eq!(answers.high_bounds_ref(), &None);

        assert_eq!(answers.set_high_bounds(Answer::Int(30)), 30);
        assert_eq!(answers.high_bounds_ref(), &Some(30));

        assert_eq!(answers.set_high_bounds(Answer::Int(31)), 30);
        assert_eq!(answers.high_bounds_ref(), &Some(30));

        assert_eq!(answers.set_high_bounds(Answer::Int(12)), 12);
        assert_eq!(answers.high_bounds_ref(), &Some(12));
    }

    #[test]
    fn set_higher_low_boundary_replaces_prev() {
        let mut answers = Answers::new();
        assert_eq!(answers.low_bounds_ref(), &None);

        assert_eq!(answers.set_low_bounds(Answer::Int(4)), 4);
        assert_eq!(answers.low_bounds_ref(), &Some(4));

        assert_eq!(answers.set_low_bounds(Answer::Int(-2)), 4);
        assert_eq!(answers.low_bounds_ref(), &Some(4));

        assert_eq!(answers.set_low_bounds(Answer::Int(187)), 187);
        assert_eq!(answers.low_bounds_ref(), &Some(187));
    }

    #[test]
    fn check_answer_uses_low_bounds_if_set() {
        let mut answers = Answers::new();
        assert!(answers.check(&Answer::Int(100)).is_none());

        answers.set_low_bounds(Answer::Int(90));

        assert_eq!(answers.check(&Answer::Int(85)), Some(CheckResult::TooLow));
        assert_eq!(answers.check(&Answer::Int(90)), Some(CheckResult::TooLow));
        assert!(answers.check(&Answer::Int(100)).is_none());

        answers.add_wrong_answer(Answer::Int(90));
        assert_eq!(answers.check(&Answer::Int(90)), Some(CheckResult::TooLow));
    }

    #[test]
    fn check_answer_uses_high_bounds_if_set() {
        let mut answers = Answers::new();
        assert!(answers.check(&Answer::Int(100)).is_none());

        answers.set_high_bounds(Answer::Int(90));

        assert_eq!(answers.check(&Answer::Int(100)), Some(CheckResult::TooHigh));
        assert_eq!(answers.check(&Answer::Int(90)), Some(CheckResult::TooHigh));
        assert!(answers.check(&Answer::Int(85)).is_none());

        answers.add_wrong_answer(Answer::Int(90));
        assert_eq!(answers.check(&Answer::Int(90)), Some(CheckResult::TooHigh));
    }

    #[test]
    fn check_answer_checks_high_and_low_bounds_if_set() {
        let mut answers = Answers::new();

        answers.set_low_bounds(Answer::Int(96));
        answers.set_high_bounds(Answer::Int(103));

        assert_eq!(answers.check(&Answer::Int(107)), Some(CheckResult::TooHigh));
        assert_eq!(answers.check(&Answer::Int(103)), Some(CheckResult::TooHigh));
        assert_eq!(answers.check(&Answer::Int(100)), None);
        assert_eq!(answers.check(&Answer::Int(98)), None);
        assert_eq!(answers.check(&Answer::Int(96)), Some(CheckResult::TooLow));
        assert_eq!(answers.check(&Answer::Int(-5)), Some(CheckResult::TooLow));
    }

    #[test]
    fn check_answer_bounds_checked_if_int_or_int_str() {
        let mut answers = Answers::new();

        answers.set_low_bounds(Answer::Int(-50));
        answers.set_high_bounds(Answer::Int(25));
        answers.add_wrong_answer(Answer::Int(-9));
        answers.add_wrong_answer(Answer::Int(1));
        answers.add_wrong_answer(Answer::from_str("xyz").unwrap());

        assert_eq!(
            answers.check(&Answer::from_str("55").unwrap()),
            Some(CheckResult::TooHigh)
        );
        assert_eq!(answers.check(&Answer::Int(55)), Some(CheckResult::TooHigh));

        assert_eq!(answers.check(&Answer::Int(10)), None);
        assert_eq!(answers.check(&Answer::from_str("10").unwrap()), None);

        assert_eq!(
            answers.check(&Answer::from_str("-74").unwrap()),
            Some(CheckResult::TooLow)
        );
        assert_eq!(answers.check(&Answer::Int(-74)), Some(CheckResult::TooLow));
    }

    #[test]
    fn wrong_answers_if_in_bounds() {
        let mut answers = Answers::new();

        answers.set_low_bounds(Answer::Int(-50));
        answers.set_high_bounds(Answer::Int(25));
        answers.add_wrong_answer(Answer::Int(-9));
        answers.add_wrong_answer(Answer::Int(1));
        answers.add_wrong_answer(Answer::Int(100));
        answers.add_wrong_answer(Answer::Int(-100));
        answers.add_wrong_answer(Answer::from_str("xyz").unwrap());

        assert_eq!(
            answers.check(&Answer::from_str("-9").unwrap()),
            Some(CheckResult::Wrong)
        );
        assert_eq!(answers.check(&Answer::Int(-9)), Some(CheckResult::Wrong));
        assert_eq!(
            answers.check(&Answer::from_str("1").unwrap()),
            Some(CheckResult::Wrong)
        );
        assert_eq!(answers.check(&Answer::Int(1)), Some(CheckResult::Wrong));
        assert_eq!(
            answers.check(&Answer::from_str("xyz").unwrap()),
            Some(CheckResult::Wrong)
        );
        assert_eq!(
            answers.check(&Answer::from_str("100").unwrap()),
            Some(CheckResult::TooHigh)
        );
        assert_eq!(answers.check(&Answer::Int(100)), Some(CheckResult::TooHigh));
        assert_eq!(
            answers.check(&Answer::from_str("-100").unwrap()),
            Some(CheckResult::TooLow)
        );
        assert_eq!(answers.check(&Answer::Int(-100)), Some(CheckResult::TooLow));
    }

    #[test]
    fn answers_are_wrong_when_there_is_correct_answer_that_does_not_match() {
        let mut answers = Answers::new();

        answers.set_correct_answer(Answer::from_str("yes").unwrap());

        assert_eq!(
            answers.check(&Answer::from_str("yes").unwrap()),
            Some(CheckResult::Correct)
        );
        assert_eq!(
            answers.check(&Answer::from_str("no").unwrap()),
            Some(CheckResult::Wrong)
        );
        assert_eq!(
            answers.check(&Answer::from_str("maybe").unwrap()),
            Some(CheckResult::Wrong)
        );
    }

    #[test]
    fn serialize_answers_to_text() {
        let text = Answers {
            correct_answer: Some(Answer::Int(12)),
            wrong_answers: vec![
                Answer::Int(-9),
                Answer::Int(1),
                Answer::Int(100),
                Answer::from_str("xyz").unwrap(),
            ],
            low_bounds: Some(-50),
            high_bounds: Some(25),
        }
        .serialize_to_string();

        assert_eq!(text, "= 12\n[ -50\n] 25\nX -9\nX 1\nX 100\nX xyz\n");
    }

    #[test]
    fn serialize_answers_to_text_with_no_correct() {
        let text = Answers {
            correct_answer: None,
            wrong_answers: vec![
                Answer::Int(-9),
                Answer::Int(1),
                Answer::Int(100),
                Answer::from_str("xyz").unwrap(),
            ],
            low_bounds: Some(-50),
            high_bounds: Some(25),
        }
        .serialize_to_string();

        assert_eq!(text, "[ -50\n] 25\nX -9\nX 1\nX 100\nX xyz\n");
    }

    #[test]
    fn serialize_answers_to_text_with_missing_correct_and_high() {
        let text = Answers {
            correct_answer: None,
            wrong_answers: vec![
                Answer::Int(-9),
                Answer::Int(1),
                Answer::Int(100),
                Answer::from_str("xyz").unwrap(),
            ],
            low_bounds: Some(-50),
            high_bounds: None,
        }
        .serialize_to_string();

        assert_eq!(text, "[ -50\nX -9\nX 1\nX 100\nX xyz\n");
    }

    #[test]
    fn deserialize_answers_from_text() {
        let answers = Answers::deserialize_from_str("= 12\n[ -50\n] 25\nX -9\nX 1\nX 100\nX xyz\n")
            .expect("no deserialization errors exepcted");

        assert_eq!(
            answers,
            Answers {
                correct_answer: Some(Answer::Int(12)),
                wrong_answers: vec![
                    Answer::Int(-9),
                    Answer::Int(1),
                    Answer::Int(100),
                    Answer::from_str("xyz").unwrap(),
                ],
                low_bounds: Some(-50),
                high_bounds: Some(25),
            }
        );
    }

    #[test]
    fn deserialize_answers_to_text_with_no_correct() {
        let answers = Answers::deserialize_from_str("[ -50\n] 25\nX -9\nX 1\nX 100\nX xyz\n")
            .expect("no deserialization errors exepcted");

        assert_eq!(
            answers,
            Answers {
                correct_answer: None,
                wrong_answers: vec![
                    Answer::Int(-9),
                    Answer::Int(1),
                    Answer::Int(100),
                    Answer::from_str("xyz").unwrap(),
                ],
                low_bounds: Some(-50),
                high_bounds: Some(25),
            }
        );
    }

    #[test]
    fn deserialize_answers_to_text_with_missing_correct_and_high() {
        let answers = Answers::deserialize_from_str("[ -50\nX -9\nX 1\nX 100\nX xyz\n")
            .expect("no deserialization errors exepcted");

        assert_eq!(
            answers,
            Answers {
                correct_answer: None,
                wrong_answers: vec![
                    Answer::Int(-9),
                    Answer::Int(1),
                    Answer::Int(100),
                    Answer::from_str("xyz").unwrap(),
                ],
                low_bounds: Some(-50),
                high_bounds: None,
            }
        );
    }

    #[test]
    fn deserialize_answers_with_spaces() {
        let answers = Answers::deserialize_from_str("= hello world\nX foobar\nX one two three\n")
            .expect("no deserialization errors exepcted");

        assert_eq!(
            answers,
            Answers {
                correct_answer: Some(Answer::from_str("hello world").unwrap()),
                wrong_answers: vec![
                    Answer::from_str("foobar").unwrap(),
                    Answer::from_str("one two three").unwrap(),
                ],
                low_bounds: None,
                high_bounds: None,
            }
        );
    }
}