Skip to content

Refactor fn split #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 18, 2023
Merged

Refactor fn split #15

merged 1 commit into from
Feb 18, 2023

Conversation

lonesometraveler
Copy link
Contributor

Now, this is not a simple clippy fix. I think you want to split a &str with ':' and ',' and take out &strs that represent f32. This PR should do that. Here is a set of simple tests I used. If I am missing something, please let me know.

#[test]
fn test_split() {
    let input = "foo: bar, baz, qux: -0.1, 0.2, -0.3";
    let expected_output = vec!["-0.1", "0.2", "-0.3"];
    let actual_output = split(input);
    assert_eq!(expected_output, actual_output);
}

#[test]
fn test_split_2() {
    let input = "foo:bar,baz,qux:-0.1,0.2,-0.3";
    let expected_output = vec!["-0.1", "0.2", "-0.3"];
    let actual_output = split(input);
    assert_eq!(expected_output, actual_output);
}

I think we should parse in this function and return Vec<f32> instead of Vec<&str>. But that requires modification in main. Let's make sure we are good with this change first.

@hacknus
Copy link
Owner

hacknus commented Feb 18, 2023

Yes, perfect! This looks much cleaner and seems to work. I agree about returning f32 and adapt main().

@hacknus hacknus merged commit 4591214 into hacknus:main Feb 18, 2023
@lonesometraveler
Copy link
Contributor Author

Cool. I will send more PRs tomorrow.

@lonesometraveler lonesometraveler deleted the refactor_split branch February 28, 2023 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants