Python 3 - Assert a boolean.
I have overridden __eq___
in a class that I'm currently doctesting. All the methods (not showed) work fine, but when I added __eq__
, I get an error message.
My method:
def __eq__(self, other):
""" Tests if two dual objects are equal or not.
Returns
-------
True or false, depending on the comparison
Examples
--------
>>> z = Dual(1, 1)
>>> y = Dual(1, 1)
>>> z == y
True
"""
# compare the real and dual parts of self versus other.
#Output True if both cases match, false otherwise.
if self.r == other.r and self.d == other.d:
return True
else:
return False
In my doctesting file, the following method is meant to test that this method works:
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
assert z == y
The error message I get is as follows:
=================================== FAILURES ===================================
___________________________________ test_eq ____________________________________
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
> assert z == y
E assert 1.00 + eps 1.00 == 1.00 + eps 1.00
spacejam/tests/dualnumbers_test.py:53: AssertionError
=============================== warnings summary ===============================
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23: DeprecationWarning: invalid escape sequence p
"""
Is there something I am doing terrifically wrong or overlooking?
python-3.x unit-testing
add a comment |
I have overridden __eq___
in a class that I'm currently doctesting. All the methods (not showed) work fine, but when I added __eq__
, I get an error message.
My method:
def __eq__(self, other):
""" Tests if two dual objects are equal or not.
Returns
-------
True or false, depending on the comparison
Examples
--------
>>> z = Dual(1, 1)
>>> y = Dual(1, 1)
>>> z == y
True
"""
# compare the real and dual parts of self versus other.
#Output True if both cases match, false otherwise.
if self.r == other.r and self.d == other.d:
return True
else:
return False
In my doctesting file, the following method is meant to test that this method works:
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
assert z == y
The error message I get is as follows:
=================================== FAILURES ===================================
___________________________________ test_eq ____________________________________
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
> assert z == y
E assert 1.00 + eps 1.00 == 1.00 + eps 1.00
spacejam/tests/dualnumbers_test.py:53: AssertionError
=============================== warnings summary ===============================
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23: DeprecationWarning: invalid escape sequence p
"""
Is there something I am doing terrifically wrong or overlooking?
python-3.x unit-testing
error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
– Sach
Nov 26 '18 at 8:30
add a comment |
I have overridden __eq___
in a class that I'm currently doctesting. All the methods (not showed) work fine, but when I added __eq__
, I get an error message.
My method:
def __eq__(self, other):
""" Tests if two dual objects are equal or not.
Returns
-------
True or false, depending on the comparison
Examples
--------
>>> z = Dual(1, 1)
>>> y = Dual(1, 1)
>>> z == y
True
"""
# compare the real and dual parts of self versus other.
#Output True if both cases match, false otherwise.
if self.r == other.r and self.d == other.d:
return True
else:
return False
In my doctesting file, the following method is meant to test that this method works:
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
assert z == y
The error message I get is as follows:
=================================== FAILURES ===================================
___________________________________ test_eq ____________________________________
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
> assert z == y
E assert 1.00 + eps 1.00 == 1.00 + eps 1.00
spacejam/tests/dualnumbers_test.py:53: AssertionError
=============================== warnings summary ===============================
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23: DeprecationWarning: invalid escape sequence p
"""
Is there something I am doing terrifically wrong or overlooking?
python-3.x unit-testing
I have overridden __eq___
in a class that I'm currently doctesting. All the methods (not showed) work fine, but when I added __eq__
, I get an error message.
My method:
def __eq__(self, other):
""" Tests if two dual objects are equal or not.
Returns
-------
True or false, depending on the comparison
Examples
--------
>>> z = Dual(1, 1)
>>> y = Dual(1, 1)
>>> z == y
True
"""
# compare the real and dual parts of self versus other.
#Output True if both cases match, false otherwise.
if self.r == other.r and self.d == other.d:
return True
else:
return False
In my doctesting file, the following method is meant to test that this method works:
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
assert z == y
The error message I get is as follows:
=================================== FAILURES ===================================
___________________________________ test_eq ____________________________________
def test_eq():
z = sj.Dual(1,1)
y = sj.Dual(1,1)
> assert z == y
E assert 1.00 + eps 1.00 == 1.00 + eps 1.00
spacejam/tests/dualnumbers_test.py:53: AssertionError
=============================== warnings summary ===============================
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23
/home/travis/virtualenv/python3.6.3/src/spacejam/spacejam/dual.py:23: DeprecationWarning: invalid escape sequence p
"""
Is there something I am doing terrifically wrong or overlooking?
python-3.x unit-testing
python-3.x unit-testing
asked Nov 26 '18 at 3:19
WorkhorseWorkhorse
462511
462511
error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
– Sach
Nov 26 '18 at 8:30
add a comment |
error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
– Sach
Nov 26 '18 at 8:30
error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
– Sach
Nov 26 '18 at 8:30
error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
– Sach
Nov 26 '18 at 8:30
add a comment |
1 Answer
1
active
oldest
votes
Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
you can do below :
assert z.r == y.r
assert z.d == z.d
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474377%2fpython-3-assert-a-boolean%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
you can do below :
assert z.r == y.r
assert z.d == z.d
add a comment |
Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
you can do below :
assert z.r == y.r
assert z.d == z.d
add a comment |
Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
you can do below :
assert z.r == y.r
assert z.d == z.d
Error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
you can do below :
assert z.r == y.r
assert z.d == z.d
answered Nov 26 '18 at 8:31
SachSach
685517
685517
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53474377%2fpython-3-assert-a-boolean%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
error is clearly showing that value of z and y are in form "1.00 + eps 1.00" which you can not directly compare.
– Sach
Nov 26 '18 at 8:30