Coder Social home page Coder Social logo

pointr-case's Introduction

pointr-case

Q1)

a) I implement it in the project in DiceRoller class with using Date().timeIntervalSince1970

DiceRoller class

b) I implement it in the project in DiceRollerTest class with using totalRolls value which is a large number of roll times. let totalRolls = 500000 // value for test count

Frequency Test: Ensures that each number between 1 to 6 approximately appears similar times. The distribution should be nearly uniform. Bounds Test: Ensures that the number must be (1,2,3,4,5,6). Repeatability Test: Ensures the result is different or ensure that the function isn't deterministic under identical conditions. Each number must not repeat too much.

DiceRollerTest methods

Also i write all test methods on the project, used logger to log informations,

App screenshot wit logs

Q2)

Safety and Predictability: With NSDictionary, once it's set, you know it will never change. This reduces the risk of unexpected side effects or data corruption from changes in different parts of the code.

Performance: Immutable objects can often be optimized better than mutable ones since they don't need to handle potential changes.

Memory Management: Immutable objects can be more memory-efficient since they don't need to reserve extra space for potential changes.

One can't be simply dropped without breaking a lot of existing code or violating the principle of immutability. The introduction of Swift and its focus on value types (like Dictionary) makes this distinction clearer, but for Objective-C compatibility and historical reasons, both types must be exist.

Q3)

It does not work on negative values also without floating point it is not possible some integer values to calculete sqrt roots if it is not perfect square numbers (like 1,4,9 etc.) the method below finds the nearest integer.

function integerSqrt(x):

if x < 0:
    return "Error" // negative value
else if x == 0 or x == 1:
    return x
start = 1
end = x
while start <= end:
    mid = (start + end) / 2 // integer division
    squared = mid * mid
    if squared == x:
        return mid
    else if squared < x:
        start = mid + 1
    else:
        end = mid - 1

return start - 1

Q4) Logger implemented in the project DebugConsoleManager class, it have different log levels, also question 1 logged using this logger.

Logger

Q5)

a)

  • Synchronous: Advantages: Simpler code. Execution waits until the request completion. Disadvantages: Blocks the main thread which can lead to a poor UX. It can make applications unresponsive. Asynchronous:
  • Asynchronous: Advantages: Doesn't block the main thread. Allows for a more responsive UI. Can handle multiple tasks at once. Disadvantages: More complex code. Need to handle callbacks, potential issues with race conditions or deadlocks.

b) now i am working an implementation like that in my current job, I used DispathGroup together semaphores in swift.

for here we should wait the all the http calls are completed

function synchronousHTTPCall(url):

semaphore = createSemaphore(value: 0)
var resultData = null
makeAsynchronousCall(url, completion: (data) => {
    resultData = data
    signalSemaphore(semaphore)
})
waitForSemaphore(semaphore)
return resultData

pointr-case's People

Contributors

rcanbaba avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.