ApproximateValueTokenSpec.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace spec\Prophecy\Argument\Token;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. class ApproximateValueTokenSpec extends ObjectBehavior
  6. {
  7. function let()
  8. {
  9. $this->beConstructedWith(10.12345678, 4);
  10. }
  11. function it_is_initializable()
  12. {
  13. $this->shouldHaveType('Prophecy\Argument\Token\ApproximateValueToken');
  14. }
  15. function it_implements_TokenInterface()
  16. {
  17. $this->shouldBeAnInstanceOf('Prophecy\Argument\Token\TokenInterface');
  18. }
  19. function it_is_not_last()
  20. {
  21. $this->shouldNotBeLast();
  22. }
  23. function it_scores_10_if_rounded_argument_matches_rounded_value()
  24. {
  25. $this->scoreArgument(10.12345)->shouldReturn(10);
  26. }
  27. function it_does_not_score_if_rounded_argument_does_not_match_rounded_value()
  28. {
  29. $this->scoreArgument(10.1234)->shouldReturn(false);
  30. }
  31. function it_uses_a_default_precision_of_zero()
  32. {
  33. $this->beConstructedWith(10.7);
  34. $this->scoreArgument(11.4)->shouldReturn(10);
  35. }
  36. function it_does_not_score_if_rounded_argument_is_not_numeric()
  37. {
  38. $this->scoreArgument('hello')->shouldReturn(false);
  39. }
  40. function it_has_simple_string_representation()
  41. {
  42. $this->__toString()->shouldBe('≅10.1235');
  43. }
  44. }