Description:
Write a function that converts a base 10 number and returns binary (base 2).
Binary is consisted of zeros and ones only, and those make up the binary number.
Suppose that place value works the same.
def binaryConverter( input ): return int( "{:b}".format(input) )
func binaryConverter(_ input: Int) -> Int {//Your Code Herereturn input}- def binaryConverter( input ):
- return int( "{:b}".format(input) )
# TODO: Replace examples and use TDD development by writing your own tests # These are some of the methods available: # test.expect(boolean, [optional] message) # test.assert_equals(actual, expected, [optional] message) # test.assert_not_equals(actual, expected, [optional] message) from random import randint test.describe("Simple Tests") test.assert_equals( binaryConverter(1) , 1 ) test.assert_equals( binaryConverter(15) , 1111 ) test.assert_equals( binaryConverter(0) , 0 ) test.assert_equals( binaryConverter(-6) , -110 ) test.describe("Random Tests") for i in range(100): rndTest = randint( -(2**16 - 1) , (2**16 - 1) ) test.assert_equals( binaryConverter(rndTest) , int( "{:b}".format(rndTest) ) ) # You can use Test.describe and Test.it to write BDD style test groupings
import XCTest// XCTest Spec Example:// TODO: replace with your own tests (TDD), these are just how-to examples to get you started- # TODO: Replace examples and use TDD development by writing your own tests
- # These are some of the methods available:
- # test.expect(boolean, [optional] message)
- # test.assert_equals(actual, expected, [optional] message)
- # test.assert_not_equals(actual, expected, [optional] message)
class SolutionTest: XCTestCase {static var allTests = [("Test Example", testExample),]- from random import randint
func testExample() {let actual = 1XCTAssertEqual(actual, 1)}}- test.describe("Simple Tests")
- test.assert_equals( binaryConverter(1) , 1 )
- test.assert_equals( binaryConverter(15) , 1111 )
- test.assert_equals( binaryConverter(0) , 0 )
- test.assert_equals( binaryConverter(-6) , -110 )
XCTMain([testCase(SolutionTest.allTests)])- test.describe("Random Tests")
- for i in range(100):
- rndTest = randint( -(2**16 - 1) , (2**16 - 1) )
- test.assert_equals( binaryConverter(rndTest) , int( "{:b}".format(rndTest) ) )
- # You can use Test.describe and Test.it to write BDD style test groupings