Skip to content

Commit abaca54

Browse files
committed
test(readme_parser): improving the readme_parser test suite by adding more tests
1 parent 15be84d commit abaca54

4 files changed

Lines changed: 265 additions & 0 deletions

File tree

tests/data/1004.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Problem 1004: Max_Consecutive_Ones_III
2+
3+
Given a binary array `nums` and an integer `k`, return *the maximum number of consecutive* `1`*'s in the array if you can flip at most* `k` `0`'s.
4+
5+
**Example 1:**
6+
7+
```
8+
Input: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
9+
Output: 6
10+
Explanation: [1,1,1,0,0,1,1,1,1,1,1]
11+
Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
12+
```
13+
14+
**Example 2:**
15+
16+
```
17+
Input: nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3
18+
Output: 10
19+
Explanation: [0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1]
20+
Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
21+
22+
```
23+
24+
**Constraints:**
25+
26+
* `1 <= nums.length <= 10<sup>5</sup>`
27+
* `nums[i]` is either `0` or `1`.
28+
* `0 <= k <= nums.length`

tests/data/1768.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Problem 1768: Merge_Strings_Alternately
2+
3+
You are given two strings `word1` and `word2`. Merge the strings by adding letters in alternating order, starting with `word1`. If a string is longer than the other, append the additional letters onto the end of the merged string.
4+
5+
Return *the merged string.*
6+
7+
**Example 1:**
8+
9+
```
10+
Input: word1 = "abc", word2 = "pqr"
11+
Output: "apbqcr"
12+
Explanation: The merged string will be merged as so:
13+
word1: a b c
14+
word2: p q r
15+
merged: a p b q c r
16+
17+
```
18+
19+
**Example 2:**
20+
21+
```
22+
Input: word1 = "ab", word2 = "pqrs"
23+
Output: "apbqrs"
24+
Explanation: Notice that as word2 is longer, "rs" is appended to the end.
25+
word1: a b
26+
word2: p q r s
27+
merged: a p b q r s
28+
29+
```
30+
31+
**Example 3:**
32+
33+
```
34+
Input: word1 = "abcd", word2 = "pq"
35+
Output: "apbqcd"
36+
Explanation: Notice that as word1 is longer, "cd" is appended to the end.
37+
word1: a b c d
38+
word2: p q
39+
merged: a p b q c d
40+
41+
```
42+
43+
**Constraints:**
44+
45+
* `1 <= word1.length, word2.length <= 100`
46+
* `word1` and `word2` consist of lowercase English letters.

tests/data/823.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Problem 823: Binary_Trees_With_Factors
2+
3+
Given an array of unique integers, `arr`, where each integer `arr[i]` is strictly greater than `1`.
4+
5+
We make a binary tree using these integers, and each number may be used for any number of times. Each non-leaf node's value should be equal to the product of the values of its children.
6+
7+
Return *the number of binary trees we can make*. The answer may be too large so return the answer **modulo** `10<sup>9</sup> + 7`.
8+
9+
**Example 1:**
10+
11+
```
12+
Input: arr = [2,4]
13+
Output: 3
14+
Explanation: We can make these trees: [2], [4], [4, 2, 2]
15+
```
16+
17+
**Example 2:**
18+
19+
```
20+
Input: arr = [2,4,5,10]
21+
Output: 7
22+
Explanation: We can make these trees: [2], [4], [5], [10], [4, 2, 2], [10, 2, 5], [10, 5, 2].
23+
```
24+
25+
**Constraints:**
26+
27+
* `1 <= arr.length <= 1000`
28+
* `2 <= arr[i] <= 10<sup>9</sup>`
29+
* All the values of `arr` are **unique**.

tests/readme_parser_tests.rs

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,165 @@ fn test_392_outputs_1_parse_readme() {
114114

115115
assert_eq!(output, expected, "second output mismatch");
116116
}
117+
118+
#[test]
119+
fn test_823_count_example() {
120+
let readme_content = std::fs::read_to_string("tests/data/823.md")
121+
.expect("Failed to read test readme file");
122+
let lrp = LeetcodeReadmeParser::new(&readme_content);
123+
124+
let result = lrp.parse();
125+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
126+
let problem_data = result.unwrap();
127+
assert_eq!(
128+
problem_data.example_count, 2,
129+
"Expected 2 test cases in the readme"
130+
);
131+
}
132+
133+
#[test]
134+
fn test_823_inputs_0_parse_readme() {
135+
let readme_content = std::fs::read_to_string("tests/data/823.md")
136+
.expect("Failed to read test readme file");
137+
let lrp = LeetcodeReadmeParser::new(&readme_content);
138+
let result = lrp.parse();
139+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
140+
let problem_data = result.unwrap();
141+
let input = &problem_data.inputs[0];
142+
let expected = "arr = [2,4]";
143+
assert_eq!(input, expected, "first input mismatch");
144+
}
145+
146+
#[test]
147+
fn test_823_outputs_1_parse_readme() {
148+
let readme_content = std::fs::read_to_string("tests/data/823.md")
149+
.expect("Failed to read test readme file");
150+
let lrp = LeetcodeReadmeParser::new(&readme_content);
151+
let result = lrp.parse();
152+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
153+
let problem_data = result.unwrap();
154+
let output = &problem_data.outputs[1];
155+
let expected = "7";
156+
assert_eq!(output, expected, "second output mismatch");
157+
}
158+
159+
#[test]
160+
fn test_1768_count_example() {
161+
let readme_content = std::fs::read_to_string("tests/data/1768.md")
162+
.expect("Failed to read test readme file");
163+
let lrp = LeetcodeReadmeParser::new(&readme_content);
164+
165+
let result = lrp.parse();
166+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
167+
let problem_data = result.unwrap();
168+
assert_eq!(
169+
problem_data.example_count, 3,
170+
"Expected 3 test cases in the readme"
171+
);
172+
}
173+
174+
#[test]
175+
fn test_1768_inputs_0_parse_readme() {
176+
let readme_content = std::fs::read_to_string("tests/data/1768.md")
177+
.expect("Failed to read test readme file");
178+
let lrp = LeetcodeReadmeParser::new(&readme_content);
179+
let result = lrp.parse();
180+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
181+
let problem_data = result.unwrap();
182+
let input = &problem_data.inputs[0];
183+
let expected = "word1 = \"abc\", word2 = \"pqr\"";
184+
assert_eq!(input, expected, "first input mismatch");
185+
}
186+
187+
#[test]
188+
fn test_1768_outputs_1_parse_readme() {
189+
let readme_content = std::fs::read_to_string("tests/data/1768.md")
190+
.expect("Failed to read test readme file");
191+
let lrp = LeetcodeReadmeParser::new(&readme_content);
192+
let result = lrp.parse();
193+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
194+
let problem_data = result.unwrap();
195+
let output = &problem_data.outputs[1];
196+
let expected = "\"apbqrs\"";
197+
assert_eq!(output, expected, "second output mismatch");
198+
}
199+
200+
#[test]
201+
fn test_1768_outputs_2_parse_readme() {
202+
let readme_content = std::fs::read_to_string("tests/data/1768.md")
203+
.expect("Failed to read test readme file");
204+
let lrp = LeetcodeReadmeParser::new(&readme_content);
205+
let result = lrp.parse();
206+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
207+
let problem_data = result.unwrap();
208+
let output = &problem_data.outputs[2];
209+
let expected = "\"apbqcd\"";
210+
assert_eq!(output, expected, "3rd output mismatch");
211+
}
212+
213+
#[test]
214+
fn test_1004_count_example() {
215+
let readme_content = std::fs::read_to_string("tests/data/1004.md")
216+
.expect("Failed to read test readme file");
217+
let lrp = LeetcodeReadmeParser::new(&readme_content);
218+
219+
let result = lrp.parse();
220+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
221+
let problem_data = result.unwrap();
222+
assert_eq!(
223+
problem_data.example_count, 2,
224+
"Expected 2 test cases in the readme"
225+
);
226+
}
227+
228+
#[test]
229+
fn test_1004_inputs_0_parse_readme() {
230+
let readme_content = std::fs::read_to_string("tests/data/1004.md")
231+
.expect("Failed to read test readme file");
232+
let lrp = LeetcodeReadmeParser::new(&readme_content);
233+
let result = lrp.parse();
234+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
235+
let problem_data = result.unwrap();
236+
let input = &problem_data.inputs[0];
237+
let expected = "nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2";
238+
assert_eq!(input, expected, "first input mismatch");
239+
}
240+
241+
#[test]
242+
fn test_1004_inputs_1_parse_readme() {
243+
let readme_content = std::fs::read_to_string("tests/data/1004.md")
244+
.expect("Failed to read test readme file");
245+
let lrp = LeetcodeReadmeParser::new(&readme_content);
246+
let result = lrp.parse();
247+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
248+
let problem_data = result.unwrap();
249+
let input = &problem_data.inputs[1];
250+
let expected = "nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1], k = 3";
251+
assert_eq!(input, expected, "first input mismatch");
252+
}
253+
254+
#[test]
255+
fn test_1004_outputs_0_parse_readme() {
256+
let readme_content = std::fs::read_to_string("tests/data/1004.md")
257+
.expect("Failed to read test readme file");
258+
let lrp = LeetcodeReadmeParser::new(&readme_content);
259+
let result = lrp.parse();
260+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
261+
let problem_data = result.unwrap();
262+
let output = &problem_data.outputs[0];
263+
let expected = "6";
264+
assert_eq!(output, expected, "second output mismatch");
265+
}
266+
267+
#[test]
268+
fn test_1004_outputs_1_parse_readme() {
269+
let readme_content = std::fs::read_to_string("tests/data/1004.md")
270+
.expect("Failed to read test readme file");
271+
let lrp = LeetcodeReadmeParser::new(&readme_content);
272+
let result = lrp.parse();
273+
assert!(result.is_ok(), "Failed to parse readme: {:?}", result.err());
274+
let problem_data = result.unwrap();
275+
let output = &problem_data.outputs[1];
276+
let expected = "10";
277+
assert_eq!(output, expected, "second output mismatch");
278+
}

0 commit comments

Comments
 (0)