Skip to content

Commit 7109151

Browse files
committed
reorganize testing
1 parent d9100c6 commit 7109151

17 files changed

+585
-596
lines changed

.github/workflows/ci.yml

-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,3 @@ jobs:
4242
crate: cargo-all-features
4343
version: latest
4444
- run: cargo test-all-features
45-
46-
- name: Test Parsing
47-
uses: actions-rs/cargo@v1
48-
with:
49-
command: test
50-
args: --package parsing

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repository = "https://github.com/Titaniumtown/YTBN-Graphing-Software"
77
description = "Crossplatform (and web-compatible) graphing calculator"
88

99
[lib]
10-
crate-type = ["cdylib"]
10+
crate-type = ["cdylib", "rlib"]
1111

1212
[features]
1313
threading = ["async-lock", "rayon"]

benchmarks/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#![test_runner(criterion::runner)]
33

44
#[allow(unused_imports)]
5-
use parsing::suggestions::split_function_chars;
5+
use parsing::split_function_chars;
66

77
#[allow(unused_imports)]
88
use std::time::Duration;

parsing/src/autocomplete_helper.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ fn compare_len_reverse_alpha(a: &String, b: &String) -> Ordering {
1111

1212
/// Generates hashmap (well really a vector of tuple of strings that are then turned into a hashmap by phf)
1313
#[allow(dead_code)]
14-
fn compile_hashmap(data: Vec<String>) -> Vec<(String, String)> {
14+
pub fn compile_hashmap(data: Vec<String>) -> Vec<(String, String)> {
1515
let mut seen = HashSet::new();
1616

1717
let tuple_list_1: Vec<(String, String)> = data
@@ -70,33 +70,3 @@ fn all_possible_splits(
7070
})
7171
.collect::<Vec<(String, String)>>()
7272
}
73-
74-
#[cfg(test)]
75-
mod tests {
76-
use super::*;
77-
78-
/// Tests to make sure hashmap generation works as expected
79-
#[test]
80-
fn hashmap_gen_test() {
81-
let data = vec!["time", "text", "test"];
82-
let expect = vec![
83-
("t", r#"Hint::Many(&["ime(", "ext(", "est("])"#),
84-
("ti", r#"Hint::Single("me(")"#),
85-
("tim", r#"Hint::Single("e(")"#),
86-
("time", r#"Hint::Single("(")"#),
87-
("te", r#"Hint::Many(&["xt(", "st("])"#),
88-
("tex", r#"Hint::Single("t(")"#),
89-
("text", r#"Hint::Single("(")"#),
90-
("tes", r#"Hint::Single("t(")"#),
91-
("test", r#"Hint::Single("(")"#),
92-
];
93-
94-
assert_eq!(
95-
compile_hashmap(data.iter().map(|e| e.to_string()).collect()),
96-
expect
97-
.iter()
98-
.map(|(a, b)| (a.to_string(), b.to_string()))
99-
.collect::<Vec<(String, String)>>()
100-
);
101-
}
102-
}

parsing/src/lib.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,14 @@
44
#![feature(const_mut_refs)]
55

66
mod autocomplete_helper;
7-
pub mod parsing;
8-
pub mod suggestions;
7+
mod parsing;
8+
mod suggestions;
9+
10+
pub use crate::{
11+
autocomplete_helper::compile_hashmap,
12+
parsing::{process_func_str, BackingFunction},
13+
suggestions::{
14+
generate_hint, get_last_term, split_function, split_function_chars, Hint, HINT_EMPTY,
15+
SUPPORTED_FUNCTIONS,
16+
},
17+
};

parsing/src/parsing.rs

-101
Original file line numberDiff line numberDiff line change
@@ -193,104 +193,3 @@ pub fn process_func_str(function_in: &str) -> String {
193193

194194
crate::suggestions::split_function(&function_in).join("*")
195195
}
196-
197-
#[cfg(test)]
198-
mod tests {
199-
use super::*;
200-
use crate::suggestions::SUPPORTED_FUNCTIONS;
201-
use std::collections::HashMap;
202-
203-
/// Returns if function with string `func_str` is valid after processing through [`process_func_str`]
204-
fn func_is_valid(func_str: &str) -> bool {
205-
BackingFunction::new(&process_func_str(func_str)).is_ok()
206-
}
207-
208-
/// Used for testing: passes function to [`process_func_str`] before running [`test_func`]. if `expect_valid` == `true`, it expects no errors to be created.
209-
fn test_func_helper(func_str: &str, expect_valid: bool) {
210-
let is_valid = func_is_valid(func_str);
211-
let string = format!(
212-
"function: {} (expected: {}, got: {})",
213-
func_str, expect_valid, is_valid
214-
);
215-
216-
if is_valid == expect_valid {
217-
println!("{}", string);
218-
} else {
219-
panic!("{}", string);
220-
}
221-
}
222-
223-
/// Tests to make sure functions that are expected to succeed, succeed.
224-
#[test]
225-
fn test_expected() {
226-
let values = HashMap::from([
227-
("", true),
228-
("x^2", true),
229-
("2x", true),
230-
("E^x", true),
231-
("log10(x)", true),
232-
("xxxxx", true),
233-
("sin(x)", true),
234-
("xsin(x)", true),
235-
("sin(x)cos(x)", true),
236-
("x/0", true),
237-
("(x+1)(x-3)", true),
238-
("cos(xsin(x)x)", true),
239-
("(2x+1)x", true),
240-
("(2x+1)pi", true),
241-
("pi(2x+1)", true),
242-
("pipipipipipix", true),
243-
("e^sin(x)", true),
244-
("E^sin(x)", true),
245-
("e^x", true),
246-
("x**2", true),
247-
("a", false),
248-
("log222(x)", false),
249-
("abcdef", false),
250-
("log10(x", false),
251-
("x^a", false),
252-
("sin(cos(x)))", false),
253-
("0/0", false),
254-
]);
255-
256-
for (key, value) in values {
257-
test_func_helper(key, value);
258-
}
259-
}
260-
261-
/// Helps with tests of [`process_func_str`]
262-
#[cfg(test)]
263-
fn test_process_helper(input: &str, expected: &str) {
264-
assert_eq!(&process_func_str(input), expected);
265-
}
266-
267-
/// Tests to make sure my cursed function works as intended
268-
#[test]
269-
fn func_process_test() {
270-
let values = HashMap::from([
271-
("2x", "2*x"),
272-
(")(", ")*("),
273-
("(2", "(2"),
274-
("log10(x)", "log10(x)"),
275-
("log2(x)", "log2(x)"),
276-
("pipipipipipi", "π*π*π*π*π*π"),
277-
("10pi", "10*π"),
278-
("pi10", "π*10"),
279-
("10pi10", "10*π*10"),
280-
("emax(x)", "e*max(x)"),
281-
("pisin(x)", "π*sin(x)"),
282-
("e^sin(x)", "e^sin(x)"),
283-
("x**2", "x^2"),
284-
("(x+1)(x-3)", "(x+1)*(x-3)"),
285-
]);
286-
287-
for (key, value) in values {
288-
test_process_helper(key, value);
289-
}
290-
291-
for func in SUPPORTED_FUNCTIONS.iter() {
292-
let func_new = format!("{}(x)", func);
293-
test_process_helper(&func_new, &func_new);
294-
}
295-
}
296-
}

parsing/src/suggestions.rs

+1-141
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub fn generate_hint<'a>(input: &str) -> &'a Hint<'a> {
202202
}
203203
}
204204

205-
fn get_last_term(chars: &[char]) -> String {
205+
pub fn get_last_term(chars: &[char]) -> String {
206206
assert!(!chars.is_empty());
207207

208208
unsafe {
@@ -253,143 +253,3 @@ impl<'a> Hint<'a> {
253253
}
254254

255255
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
256-
257-
#[cfg(test)]
258-
mod tests {
259-
use std::collections::HashMap;
260-
261-
use super::*;
262-
263-
/// Tests to make sure hints are properly outputed based on input
264-
#[test]
265-
fn hints() {
266-
let values = HashMap::from([
267-
("", Hint::Single("x^2")),
268-
("si", Hint::Many(&["n(", "nh(", "gnum("])),
269-
("log", Hint::Many(&["2(", "10("])),
270-
("cos", Hint::Many(&["(", "h("])),
271-
("sin(", Hint::Single(")")),
272-
("sqrt", Hint::Single("(")),
273-
("ln(x)", Hint::None),
274-
("ln(x)cos", Hint::Many(&["(", "h("])),
275-
("ln(x)*cos", Hint::Many(&["(", "h("])),
276-
("sin(cos", Hint::Many(&["(", "h("])),
277-
]);
278-
279-
for (key, value) in values {
280-
println!("{} + {:?}", key, value);
281-
assert_eq!(super::generate_hint(key), &value);
282-
}
283-
}
284-
285-
#[test]
286-
fn hint_to_string() {
287-
let values = HashMap::from([
288-
("x^2", Hint::Single("x^2")),
289-
(
290-
r#"["n(", "nh(", "gnum("]"#,
291-
Hint::Many(&["n(", "nh(", "gnum("]),
292-
),
293-
(r#"["n("]"#, Hint::Many(&["n("])),
294-
("None", Hint::None),
295-
]);
296-
297-
for (key, value) in values {
298-
assert_eq!(value.to_string(), key);
299-
}
300-
}
301-
302-
#[test]
303-
fn invalid_function() {
304-
SUPPORTED_FUNCTIONS
305-
.iter()
306-
.map(|func1| {
307-
SUPPORTED_FUNCTIONS
308-
.iter()
309-
.map(|func2| func1.to_string() + func2)
310-
.collect::<Vec<String>>()
311-
})
312-
.flatten()
313-
.filter(|func| !SUPPORTED_FUNCTIONS.contains(&func.as_str()))
314-
.for_each(|key| {
315-
let split = super::split_function(&key);
316-
317-
if split.len() != 1 {
318-
panic!("failed: {} (len: {}, split: {:?})", key, split.len(), split);
319-
}
320-
321-
let generated_hint = super::generate_hint(&key);
322-
if generated_hint.is_none() {
323-
println!("success: {}", key);
324-
} else {
325-
panic!("failed: {} (Hint: '{}')", key, generated_hint.to_string());
326-
}
327-
});
328-
}
329-
330-
#[test]
331-
fn split_function() {
332-
let values = HashMap::from([
333-
("cos(x)", vec!["cos(x)"]),
334-
("cos(", vec!["cos("]),
335-
("cos(x)sin(x)", vec!["cos(x)", "sin(x)"]),
336-
("aaaaaaaaaaa", vec!["aaaaaaaaaaa"]),
337-
("emax(x)", vec!["e", "max(x)"]),
338-
("x", vec!["x"]),
339-
("xxx", vec!["x", "x", "x"]),
340-
("sin(cos(x)x)", vec!["sin(cos(x)", "x)"]),
341-
("sin(x)*cos(x)", vec!["sin(x)", "cos(x)"]),
342-
("x*x", vec!["x", "x"]),
343-
("10*10", vec!["10", "10"]),
344-
]);
345-
346-
for (key, value) in values {
347-
assert_eq!(super::split_function(key), value);
348-
}
349-
}
350-
351-
#[test]
352-
fn hint_tests() {
353-
{
354-
let hint = Hint::None;
355-
assert!(hint.is_none());
356-
assert!(!hint.is_some());
357-
assert!(!hint.is_single());
358-
}
359-
360-
{
361-
let hint = Hint::Single(&"");
362-
assert!(!hint.is_none());
363-
assert!(hint.is_some());
364-
assert!(hint.is_single());
365-
}
366-
367-
{
368-
let hint = Hint::Many(&[""]);
369-
assert!(!hint.is_none());
370-
assert!(hint.is_some());
371-
assert!(!hint.is_single());
372-
}
373-
}
374-
375-
#[test]
376-
fn get_last_term() {
377-
let values = HashMap::from([
378-
("cos(x)", "x)"),
379-
("cos(", "cos("),
380-
("aaaaaaaaaaa", "aaaaaaaaaaa"),
381-
("x", "x"),
382-
("xxx", "x"),
383-
("x*x", "x"),
384-
("10*10", "10"),
385-
("sin(cos", "cos"),
386-
]);
387-
388-
for (key, value) in values {
389-
assert_eq!(
390-
super::get_last_term(key.chars().collect::<Vec<char>>().as_slice()),
391-
value
392-
);
393-
}
394-
}
395-
}

push.sh

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
set -e #kill script if error occurs
33

44
cargo test-all-features
5-
cargo test --package parsing
65

76
bash build.sh release
87

0 commit comments

Comments
 (0)