6 kyu

When greatest is less than smallest

160 of 340NaMe613
Description
Loading description...
Mathematics
Logic
Algorithms
  • Please sign in or sign up to leave a comment.
  • danik00111 Avatar

    my function passes everything except the huge number suites, where it only gets the first ~17 digits correct. why?

  • user9644768 Avatar

    Please use new python test framework.

  • eubie Avatar

    Hey, Im having the same problem here. Upon clicking RunTests, I get "All Ok" in 500 ms, when I Submit, I get "all tests passed" but at the same time "process took more than 8 000 ms". I have no clue where the problem is. Im writing in C#.

  • zedlang Avatar

    What is the criterion for success with this kata? I have code that very clearly works since I can press the Submit button and pass roughly 450 tests. However, at this point the system times out because the process has taken more than 6000ms. Whilst I'm happy to accept that there may be inefficiencies in my code, all the tests seem to be just variations on the same theme and it just seems to be the sheer number that is the issue. How many more tests do I have to pass?

  • kimhammar Avatar

    Really fun kata but the tests takes too long to run so they time out and I can't submit. Maybe change the tests to smaller numbers?

  • archdukejfranz Avatar

    This comment has been hidden.

  • bkaes Avatar

    If a random Haskell test fails, the user won't know whether greatest or smallest failed. Split the random tests.

    Example

    import Kata.WhenGreatestIsLessThanSmallest (smallest, greatest)
    import Test.Hspec
    import Test.QuickCheck
    
    tester :: String -> Integer -> Integer -> Integer -> Integer -> Spec
    tester f x y n a = 
      it ("should return " ++ show a ++ " when x = " ++ show x ++ ", y = " ++ show y ++ ", n = " ++ show n) $
        func x y n `shouldBe` a
        where func = if f == "greatest" then greatest else smallest
    
    main :: IO ()
    main = hspec $ do 
      describe "smallest" $ do
        let test = tester "smallest"
        test 2 3 20 24
        test 13 17 100 221
        test 10 100 100 200
        -- other static tests omitted
        
        randomTests randomTestSmallest -- <- execute the random tests for smallest
      
      describe "greatest" $ do
        let test = tester "greatest"
        test 2 3 20 18
        test 13 17 100 0
        test 10 100 100 0
        -- other static tests omitted
    
        randomTests randomTestGreatest -- <- execute the random tests for greatest
    
    -- | A single random test tests the result of the actual function against
    --   the expected one. It also takes a range for x, y and one for n:
    randomTest :: (Integer -> Integer -> Integer -> Integer)
               -> (Integer -> Integer -> Integer -> Integer)
               -> (Integer, Integer) -> (Integer, Integer) -> Property
    randomTest actual expected xyrange nrange = property $
      forAll (choose xyrange) $ \x ->
        forAll (choose xyrange) $ \y ->
          forAll (choose nrange) $ \n ->        
            actual x y n `shouldBe` expected x y n
    
    -- | A random test for "greatest" tests the user's "greatest" against
    --   a hidden solution.
    randomTestGreatest :: (Integer, Integer) -> (Integer, Integer) -> Property
    randomTestGreatest = randomTest greatest solution   
      where solution x y n = -- solution here
    
    -- | A random test for "smallest" tests the user's "smallest" against
    --   a hidden solution.
    randomTestSmallest :: (Integer, Integer) -> (Integer, Integer) -> Property
    randomTestSmallest = randomTest smallest solution   
      where solution x y n = -- solution here
    
    -- | Take a ranged test and execute it for some predefined ranges.
    randomTests :: ((Integer, Integer) -> (Integer, Integer) -> Property) -> Spec
    randomTests prop = do
        it "works for small random values" $ 
            prop (1, 10^6) (10^6, 10^8)
        it "works for medium random values" $ 
            prop (10^7, 10^10) (10^13, 10^20)
        it "works for large random values" $ 
            prop (10^15, 10^21) (10^25, 10^37)
        it "works for huge random values" $ 
            prop (10 ^ 10, 50 ^ 50) (10 ^ 20, 1000 ^ 100)
    
  • bkaes Avatar

    Change the type of greatest and smallest to Integer -> Integer -> Integer -> Maybe Integer.

  • TheBMachine Avatar

    Really sweet kata. Quite a challenge to get right without timing out, but I managed :)

  • raulbc777 Avatar

    A good one! Very challenging due to the high amount of tests. I think in the examples tests, there's one that should be corrected. For me it's 5kyu.

  • CIS 122 Avatar

    This comment has been hidden.

  • CIS 122 Avatar

    This comment has been hidden.

  • SleepingCode Avatar

    In the Example Tests section the fifth and sixth test are wrong:

    test.assert_equals(greatest(10,10,1000),0)
    test.assert_equals(smallest(10,10,1000),200)
    

    should be

    test.assert_equals(greatest(10,10,1000),990)
    test.assert_equals(smallest(10,10,1000),1010)