Skip to content
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

improvement on complex-numbers tests #80

Merged
merged 1 commit into from
Mar 7, 2019
Merged

improvement on complex-numbers tests #80

merged 1 commit into from
Mar 7, 2019

Conversation

Average-user
Copy link
Member

While mentoring at exercism, i saw someone came up with a "solution" to complex-numbers that made absolutely no sense, but still passed all tests. I believe this was on purpose but he hasen't confirmed that yet.

This is the code he uploaded:

real((X,_), X).

imaginary((_, Y), Y).

add((X, _), (Y, _), (Z, _)) :-
    nonvar(X), nonvar(Y), !,
    Z is X + Y.

add((X, _), (Y, _), (Z, _)) :-
    nonvar(Y), nonvar(Z), !,
    X is Z - Y.

add((X, _), (Y, _), (Z, _)) :-
    nonvar(X), nonvar(Z),
    Y is Z - X.

sub((X, _), (Y, _), (Z, _)) :-
    nonvar(Y), !,
    Y1 is -Y,
    add((X, _), (Y1, _), (Z, _)).

sub((X, _), (Y, _), (Z, _)) :-
    Y is X - Z.

mul((X, _), (Y, _), (Z, _)).

div((X, _), (Y, _), (Z, _)).

abs((X, _), 5).

conjugate((X, _), (Y, _)).

This passes the tests because they only check if the program recognize valid solutions for add sub ... etc. But not if its able to find those solutions. And in case of abs, because it only has tests with 5 as a result.

I believe I've fixed both cases.

@Average-user Average-user merged commit e59300a into exercism:master Mar 7, 2019
@Average-user Average-user mentioned this pull request Mar 7, 2019
11 tasks
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.

None yet

1 participant