I am writing a unit test to determine if a string value appears with 2 significant figures, ie. “N.NN”
strokeValue = [NSString stringWithFormat:@"%.2f",someFloatValue];
How can I write a test that asserts, my string always has 2 decimal places?
Since you are formatting a float value using the
%.2fformat specifier, by definition, the resulting string will always have two decimal places. IfsomeFloatValueis 5 you will get 5.00. IfsomeFloatValueis 3.1415926 you will get 3.14.There is no need to test. It will always be true with the given format specifier.
Edit: It occurs to me that you may actually want to confirm that in fact you are using the correct format specifier. One way to check the resulting string would be: