module ReverseDigs where revDigs :: Integer -> Integer revDigs = read . rev . show where rev :: [Char] -> [Char] rev [] = [] rev (x:xs) = ((rev xs) ++ [x])
public class Algorithms {public static int reverseInt(int n) {int reversed = 0;while(n != 0){reversed = reversed * 10 + (n % 10);n /= 10;}return reversed;}}- module ReverseDigs where
- revDigs :: Integer -> Integer
- revDigs = read . rev . show
- where
- rev :: [Char] -> [Char]
- rev [] = []
- rev (x:xs) = ((rev xs) ++ [x])
module ReverseDigsSpec where import ReverseDigs import Test.Hspec import Test.QuickCheck palindrome :: Integer -> Integer palindrome x = read $ s ++ reverse s where s = show x -- TODO: Replace examples and use TDD development by writing your own tests spec :: Spec spec = do describe "Reverse ints" $ do it "Should reverse ints" $ do revDigs 54321 `shouldBe` (12345 :: Integer) it "Should leave palindromic numbers" $ property $ forAll (choose (1, 1000)) $ \int -> revDigs (palindrome int) `shouldBe` (palindrome int)
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;- module ReverseDigsSpec where
- import ReverseDigs
- import Test.Hspec
- import Test.QuickCheck
// TODO: Replace examples and use TDD development by writing your own tests- palindrome :: Integer -> Integer
- palindrome x = read $ s ++ reverse s
- where s = show x
- -- TODO: Replace examples and use TDD development by writing your own tests
public class SolutionTest {@Testpublic void reverseIntTest() {assertEquals(54321, Algorithms.reverseInt(12345));}}- spec :: Spec
- spec = do
- describe "Reverse ints" $ do
- it "Should reverse ints" $ do
- revDigs 54321 `shouldBe` (12345 :: Integer)
- it "Should leave palindromic numbers" $ property $
- forAll (choose (1, 1000)) $ \int ->
- revDigs (palindrome int) `shouldBe` (palindrome int)
Returns 100
module Return100 where import Data.List returnHundred :: Integer -> Integer returnHundred _ = sum $ map (^3) [1..4]
function returnhundred() {return 10 ** 2;}- module Return100 where
- import Data.List
- returnHundred :: Integer -> Integer
- returnHundred _ = sum $ map (^3) [1..4]
-- TODO: Add your tests here module Return100Spec where import Return100 import Test.Hspec import Test.QuickCheck spec :: Spec spec = do describe "returns100" $ do it "returns 100" $ do returnHundred 0 `shouldBe` (100 :: Integer)
// TODO: Add your tests here// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)// are still available for now.//// For new tests, using [Chai](https://chaijs.com/) is recommended.// You can use it by requiring:// const assert = require("chai").assert;// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.Test.assertEquals(returnhundred(),100)- -- TODO: Add your tests here
- module Return100Spec where
- import Return100
- import Test.Hspec
- import Test.QuickCheck
- spec :: Spec
- spec = do
- describe "returns100" $ do
- it "returns 100" $ do
- returnHundred 0 `shouldBe` (100 :: Integer)