Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Should we use assertEquals or assertTrue for comparing primitive types specifically ints?
Is there a preference, if so why ? I'd like to know the pros and cons of each approach.
assertEquals() gives a useful default error message on failure, like "expected X but got Y", but assertTrue() can't. Use the more specific applicable method here, which is assertEquals().
assertEquals() is to test the equality of your expected value with the returning value. Whereas assertTrue() is to check for a condition. Having said that, you can also say
If you have a condition like.
String x = "abc";
String y = "abc";
assertEquals(x, y);
You can also change it to
assertTrue(x.equals(y));
It is just another way of asserting what you expect.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I've got this example:
try {
images = this.getFinderFiles(path);
} catch (DirectoryNotFoundException exception) {
return [];
}
There is something wrong with this code?
I would recommend not to use exception handling for expected error situations. Exception handling takes time, stack unwinding has to be done.
In your case, if you usually can expect that 'path' usually exists and therefore the method can return a decent result - so you do not expect that 'this.getFinderFiles' fails - then it is fine to use exceptions here. But otherwise test the path for existence first before calling 'getFinderFiles'. That should be faster and for my taste more readable.
Btw. can you check the existence of 'path' within 'getFinderFiles' and eventually return '[]' already there?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I've got an assignment that is due tomorrow..
I don't want the entire solution, there's just a part of the program that i dont understand.
It's highlighted in the image below:
(I dont know what "save the values into the parameters of a method" means)
As you can see the type of the parameters is double& which means you are storing the values within the arguments you are sending. e.g, if you have 3 doubles a,b & c, when you call getAll(a,b,c) the result should be stored in them.
You can find more detailed explanation about &(reference) operator in
What does '&' do in a C++ declaration? .
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I'm a little confused about this.
I have a server returning a JSON string that represents an array of custom objects that I have defined. I need to perform some tests and check if each element of this array can be correctly cast/parsed to my object.
What is the correct way to do this?
I thought about creating a new Object and passing my JSON.parse(element) result to the constructor, but then how do I check if it was correctly created? Does it throw an exception?
Here is the simple way to check it:
checkJsonObject(string) {
try {
JSON.parse(string);
} catch (e) {
return false;
}
return true;
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have something like this
isLastPermutation (h:t)=
catch (nextPermutation (h:t)) (\e-> return True)
return False
In some cases nextPermutation throws an exception and I want my function isLastPermutation to return true if nextPermutation throws exception otherwise false.
Don't use exceptions for flow-control in otherwise pure Haskell. Use Maybe or Either.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Implicit coercion of a value with static type object to a possibly unrelated number type
but iv defined it in
private var width:Object;
public function SetEnemyStartPosition():void
{
var stage:Object;
this.x = stage.stageWidth * .2 - (this.width * .2);
You've created a variable of the generic type Object, but you're treating it as a number.
From the code provided, it doesn't seem like you ever set a value to the variable width which makes the:
(this.width * .2)
part of your code wrong, it is null, and of the wrong type to do arithmetic operations on to begin with. I'd suggest changing the variable declaration to this:
private var width:Number;
and making sure width isn't null before you start using it.