Q1)
a) I implement it in the project in DiceRoller class with using Date().timeIntervalSince1970
![DiceRoller class](https://private-user-images.githubusercontent.com/32519328/278285811-7731f786-2ca2-4ed1-9929-11441f31252c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2OTQyMDcsIm5iZiI6MTcyNDY5MzkwNywicGF0aCI6Ii8zMjUxOTMyOC8yNzgyODU4MTEtNzczMWY3ODYtMmNhMi00ZWQxLTk5MjktMTE0NDFmMzEyNTJjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI2VDE3MzgyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk4YzM0ZGY2M2FkYTczNDk5ZDdkZjUyNjQzNmRkMTE4MGRhNGNhNzlkYmEyN2Y5ZGE1ZTlmYTVkMjdmYTlhZmQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.PPD8AS38gdz_50d6b22_mZIuG2l1LcgejJkUQW2Tvi4)
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](https://private-user-images.githubusercontent.com/32519328/278286041-7d517cbc-9674-46e7-bc6b-03c12c377a7a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2OTQyMDcsIm5iZiI6MTcyNDY5MzkwNywicGF0aCI6Ii8zMjUxOTMyOC8yNzgyODYwNDEtN2Q1MTdjYmMtOTY3NC00NmU3LWJjNmItMDNjMTJjMzc3YTdhLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI2VDE3MzgyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWE2YTYzYzUwMzA2OGYxOTM0Yjc5MmNmYTUxN2E4MmVkOTM3ODQ4Yzk4YmYwMmU0OTJjZTQxNGJhOWVkZDJkMWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.VqCIZEyYzB2iF5FrGkF0hCLUCPOx7XPktitqfpu_xro)
Also i write all test methods on the project, used logger to log informations,
![App screenshot wit logs](https://private-user-images.githubusercontent.com/32519328/278288257-34495007-f3b1-4129-b6c3-258e00794ade.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2OTQyMDcsIm5iZiI6MTcyNDY5MzkwNywicGF0aCI6Ii8zMjUxOTMyOC8yNzgyODgyNTctMzQ0OTUwMDctZjNiMS00MTI5LWI2YzMtMjU4ZTAwNzk0YWRlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI2VDE3MzgyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWYxYjA4NzJkY2QwZjkzZDM4ZTMxODRmMDcyN2U5ZDU1MTNlMGUzMGUyYzg5ZTE1MmMzNjYyZGQxZjJlMzU1ZGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.uB4GEP7lXNpS2oLgcr_cjArmsVPV3HwsdnQF2_lFde8)
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](https://private-user-images.githubusercontent.com/32519328/278293314-98f28930-0fc6-46ab-8c83-01dd44e7c531.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2OTQyMDcsIm5iZiI6MTcyNDY5MzkwNywicGF0aCI6Ii8zMjUxOTMyOC8yNzgyOTMzMTQtOThmMjg5MzAtMGZjNi00NmFiLThjODMtMDFkZDQ0ZTdjNTMxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI2VDE3MzgyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWM4MDg2OTk1MmIwZmEzMjliYjg4ZjBiZmI5Yzg4NDU0ZjNlY2JkYzEyZTQ4NjI2ZWM3YmY1NTkxYjQzYjAyZjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.zY3lwgHqz7hElKdu58J8lOrdXjetF7X4911ynJI-dQs)
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