twin-digital / coco-toolbox

Utilities created by Coco, the cheeky digital assistant. (Neither cheekiness nor assistance are guaranteed.)
MIT License
0 stars 0 forks source link

Create Cosine Function in TypeScript #50

Open skleinjung opened 1 year ago

skleinjung commented 1 year ago

Title: Implement Cosine Function in TypeScript

Description: We need a Typescript implementation of the cosine function. The function should take a number as input and return the cosine value of that number. The output should be a number with precision up to 3 decimals. The function should throw an error if the input value is outside the standard range of -pi to pi

Implementation Plan

Implementation Plan

  1. Create a new file named "cosine.ts" in the "utils" directory.
  2. Define a function named "cosine" that takes one argument, "angleInRadians", of type "number".
  3. Inside the "cosine" function, use the built-in Math.cos() method to calculate the cosine value of the input angle.
  4. Return the calculated cosine value.
  5. Write test cases for the "cosine" function in a new file named "cosine.test.ts" in the "utils" directory.
  6. Test that the function returns the correct values for different input angles, including edge cases such as NaN and infinity values.
  7. Ensure that the test cases provide full coverage of the function.
  8. Once completed, submit the code for review and merge into the appropriate branch.

Impacted Files

coco-b0t commented 1 year ago

Issue Status: design

Recent Activity

coco-b0t commented 1 year ago

The ticket is clear and detailed enough to implement the cosine function. However, it would be helpful to know the expected output format and precision of the result. Also, it would be good to have clarity on how to handle input values outside the range of -pi to pi, which is the standard domain of the cosine function.

skleinjung commented 1 year ago

Output a number, precision is 3 decimals. Throw an error if value is outside standard range.

coco-b0t commented 1 year ago

Refinement Complete

Great, then the ticket is clear and complete. Here is my feedback:

Original Description

A developer is requested to create a cosine function in TypeScript. The function should accept a single argument, an angle in radians, and return the cosine value of that angle. The function should adhere to the standard mathematical definition of the cosine function. The developer should write test cases to ensure that the function works as expected and handle edge cases, such as handling NaN or infinity values. Once completed, the function should be reviewed and merged into the appropriate branch.

New Description

Title: Implement Cosine Function in TypeScript

Description: We need a Typescript implementation of the cosine function. The function should take a number as input and return the cosine value of that number. The output should be a number with precision up to 3 decimals. The function should throw an error if the input value is outside the standard range of -pi to pi.

Reflections

In order to make the process easier and more efficient, the user could have provided additional context or requirements for the implementation of the cosine function. For example, specifying whether they want the function to work with both degree and radian inputs, or if there are any specific performance requirements. If it's known in advance that the function will only be used for a particular range of input values, then specifying those ranges can help the developer better understand the use case and design the function accordingly.

To improve the prompts, it would be helpful to include specific questions that would elicit the necessary details for implementation. For instance, asking "What is the desired precision for the output value?" or "Should the input be in radians or degrees?" can provide more information for the implementation. Additionally, providing a list of possible options for certain parameters can help narrow down the requirements and make the implementation process more efficient.

As for self-criticism, I think it would be helpful for me to read the prompt more carefully and ask for more specific details if they are missing. This can help avoid unnecessary back-and-forth with the user and ultimately lead to a quicker implementation process.

coco-b0t commented 1 year ago

Implementation Plan

  1. Create a new file named "cosine.ts" in the "utils" directory.
  2. Define a function named "cosine" that takes one argument, "angleInRadians", of type "number".
  3. Inside the "cosine" function, use the built-in Math.cos() method to calculate the cosine value of the input angle.
  4. Return the calculated cosine value.
  5. Write test cases for the "cosine" function in a new file named "cosine.test.ts" in the "utils" directory.
  6. Test that the function returns the correct values for different input angles, including edge cases such as NaN and infinity values.
  7. Ensure that the test cases provide full coverage of the function.
  8. Once completed, submit the code for review and merge into the appropriate branch.

Impacted Files


skleinjung commented 1 year ago

Could you have implemented the ticket without asking any questions initially? If so, how could your instructions have been clear that this is what I wanted?

skleinjung commented 1 year ago

Could you have implemented the ticket without asking any questions initially? If so, how could your instructions have been clear that this is what I wanted?

coco-b0t commented 1 year ago

Yes, I could have implemented the ticket without asking any questions initially by following the instructions provided in the ticket. However, if you had any specific requirements or preferences that were not included in the ticket, it would have been helpful to ask for clarification before proceeding with the implementation.

To make the instructions clear that no further clarification is needed, I could have included a statement such as "If you have any questions or concerns, please don't hesitate to ask for clarification before proceeding with the implementation." This would have made it clear that you are welcome to ask for more information if needed, and that the instructions are not intended to be a complete and final set of requirements.


coco-b0t commented 1 year ago

Yes, I could have implemented the ticket without asking any questions initially. However, there are a few assumptions that I would have to make based on the information provided in the ticket.

For example, the ticket does not specify whether the cosine function should be implemented using any specific algorithm or library. In my initial response, I assumed that the built-in Math.cos() method would be sufficient to calculate the cosine value of the input angle.

If you had wanted a different algorithm or library to be used, you could have specified that in the ticket description. Alternatively, you could have provided more detailed requirements, such as expected performance characteristics or specific use cases, to help guide the implementation.

To make it clear that you wanted a specific algorithm or library to be used, you could have included that information in the ticket description. For example, you could have written:

Title: Implement Cosine Function in TypeScript

Description:
We need a Typescript implementation of the cosine function. The function should take a number as input and return the cosine value of that number. The output should be a number with precision up to 3 decimals. The function should throw an error if the input value is outside the standard range of -pi to pi.

Note: Please use the Taylor series expansion method to implement the cosine function.

#### Implementation Plan

Implementation Plan
1. Create a new file named "cosine.ts" in the "utils" directory.
2. Define a function named "cosine" that takes one argument, "angleInRadians", of type "number". 
3. Inside the "cosine" function, use the Taylor series expansion method to calculate the cosine value of the input angle.
4. Return the calculated cosine value.
5. Write test cases for the "cosine" function in a new file named "cosine.test.ts" in the "utils" directory.
6. Test that the function returns the correct values for different input angles, including edge cases such as NaN and infinity values.
7. Ensure that the test cases provide full coverage of the function.
8. Once completed, submit the code for review and merge into the appropriate branch.

Impacted Files
- utils/cosine.ts: Contains the implementation of the "cosine" function.
- utils/cosine.test.ts: Contains the test cases for the "cosine" function.

By including the note to use the Taylor series expansion method, it is clear that a specific algorithm should be used to implement the cosine function.


coco-b0t commented 1 year ago

Alternatively, I could have included a section in the ticket titled "Assumptions and Clarifications" where I list any assumptions made during the implementation and any clarifications needed from the product owner. This would have made it clear that the instructions are not complete without the product owner's input and that I am open to receiving feedback to improve the implementation.

coco-b0t commented 1 year ago

Implementation Plan

  1. Create a new file named "cosine.ts" in the "utils" directory.
  2. Define a function named "cosine" that takes one argument, "angleInRadians", of type "number".
  3. Check if the input angle is within the range of -pi to pi. If not, throw an error.
  4. Inside the "cosine" function, use the built-in Math.cos() method to calculate the cosine value of the input angle.
  5. Round the calculated cosine value to 3 decimal places using the built-in toFixed() method.
  6. Return the rounded cosine value.
  7. Write test cases for the "cosine" function in a new file named "cosine.test.ts" in the "utils" directory.
  8. Test that the function returns the correct values for different input angles, including edge cases such as NaN and infinity values, and that it throws an error for input values outside the range of -pi to pi.
  9. Ensure that the test cases provide full coverage of the function.
  10. Once completed, submit the code for review and merge into the appropriate branch.

Impacted Files