Question
Hello please I need help with the following question coding I need you to use Erlang only, if possible answer all the questions please where
Hello please I need help with the following question coding I need you to use Erlang only,
if possible answer all the questions please
where total = price + price * tax_amount add appropriate test cases to the test file
here I have the test file for you..
module(lab05_tests).
money_1_test() -> ?assertEqual({8, 30}, lab05:money({3, 20}, {5, 10})).
money_2_test() ->
?assertEqual({9, 0}, lab05:money({3, 20}, {5, 80})).
money_3_test() ->
?assertEqual({9, 98}, lab05:money({3, 99}, {5, 99})).
isOlder_2_test() ->
true = lab05:isOlder({10, 3, 2016}, {11, 3, 2016}).
isOlder_3_test() ->
true = lab05:isOlder({10, 1, 2016}, {10, 2, 2016}).
isOlder_4_test() ->
false = lab05:isOlder({10, 3, 2016}, {11, 2, 2016}).
isOlder_5_test() ->
true = lab05:isOlder({10, 12, 2015}, {10, 12, 2016}).
isOlder_6_test() ->
true = lab05:isOlder({11, 12, 2015}, {10, 12, 2016}).
isOlder_7_test() ->
true = lab05:isOlder({12, 11, 2016}, {12, 10, 2017}).
isOlder_8_test() ->
true = lab05:isOlder({12, 10, 2016}, {11, 3, 2017}).
findCeil_1_test() ->
[] = lab05:findCeiling([]).
findCeil_2_test() ->
[2.0, 3.0, 4.0, -1.0] = lab05:findCeiling([1.9,2.1,3.5,-1.3]).
findCeil_3_test() ->
[2.0] = lab05:findCeiling([1.2]).
findCeil_4_test() ->
[2.0, 3.0, 4.0] = lab05:findCeiling([1.2, 2.4, 3.3]).
here I have the data for step 7 and 8 as a text for you..
8.. getnth_1_test() -> {error, no_such_element} = lab05:getnth( [ ], 2). getnth_2_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"], 3). getnth_3_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"], 0). getnth_4_test() -> "there" = lab05:getnth( ["hello", "there"], 2). getnth_5_test() -> "there" = lab05:getnth( ["hello", "there", "where"], 2). getnth_6_test() -> "where" = lab05:getnth( ["hello", "there", "where"], 3). getnth_7_test() -> "where" = lab05:getnth( ["hello", "there", "where", "here"], 3)
9..repeat_1_test() -> [2, 2, 2, 2, 3] = lab05:repeat([1, 2, 3], [0, 4, 1]). repeat_2_test() -> [ ] = lab05:repeat( [ ], [0, 4, 1]). repeat_3_test() -> [ ] = lab05:repeat( [1, 2, 3], [ ]). repeat_4_test() -> [4,4] = lab05:repeat( [4,5,6], [2]).
In the text editor of your choosing create a file labo5.erl and write function definitions described below - make sure you use the exact same names as indicated in function descriptions. Instead of exporting each function one by one, use command -compile(export_all) at the top of your file that will export all functions together. Download the file labo5_tests.erl, add Erlang unit test library to it, and as you work on your solutions, write unit tests for your functions (unit tests for the first three functions are provided in the test file and for the last 2 functions in this description - note that copying and pasting from the description may introduce invisible characters in which case it is better to re-type the tests). 1. Function money that that takes two tuples, where each tuple represents a money object (each tuple consists of 2 values: dollars and cents) and calculates and returns a new tuple that constitutes the addition of the incoming money objects (dollars + dollars, cents + cents). Assume valid positive integers will be passed and do NOT error check. Normalize the values, i.e. if the cents addition results in a value > 99, adjust dollars and cents properly (hint: to pattern match a function on a tuple consisting of 2 elements, you can use function Name ( {x, Y}) -> ... type of a syntax) 2. Function isolder that takes two dates (each date is a 3-int tuple dd, mm, yyyy) and evaluates to true or false. It evaluates to true if the first argument is a date that comes before the second argument (e.g. 30/3/2012 comes before 1/4/2012, hence a person born on 30/3/2012 is older). (If two dates are the same, the result is false.). Assume the user of your function will enter valid input. Think about how you can use relational operators on entire tuples to simplify processing instead of writing nested ifs 3. Function find Ceiling that takes a list of numbers and returns the modified list constructed by applying the function ceiling to each incoming list element. For example, if original list contains (1.9, 2.1, 3.5), then the resulting list will contain (2.0, 3.0, 4.0]; you are NOT allowed to use ++ or built-in functions or list comprehension (you should use the cons operator to build the new list; you are allowed to use math:ceil though) 4. Function myMin that takes a list and returns its minimum value - use tail recursion to find list minimum and return an atom empty_list if a list is empty; you are NOT allowed to use built-in functions; add appropriate test cases to the test file that use assertEqual macro 5. Function remove Div3 that takes a list of numbers and returns the original list with all values divisible by 3 removed, e.g. if the original list contains [0, 1, 2, -3, 6], then [1, 2] is returned; you are NOT allowed to use built-in functions or list comprehension; add appropriate test cases to the test file that use true matching pattern (i.e. the other method that does NOT use assertEqual) 6. Function calculateBill that takes a list of tuples, where a tuple is of the form name, price, tax_rate, and returns a list of tuples, where each tuple is of the form name, total, 7. Function generate takes three ints as arguments and generates a list of integers from arg1 to arg2 (inclusive) in increments indicated by arg3, e.g. if arg1 = 3, arg2 = 8, and arg 3 = 2, then the function returns [3, 5, 7). If arg1 > arg2, returns an empty list; assume arg3 will be a valid number; you are NOT allowed to use built-in functions or list comprehension; add appropriate test cases to the test file 8. Function getnth that takes a list and an int n and returns the nth element of the list, where the head of the list is the 1st element. You are only allowed to use list functions hd and tl in your solution - no other built-in functions are allowed. If the list is empty or n is invalid, return a tuple: {error, no_such_element} add the following test cases to the test file: getnth_1_test() -> {error, no_such_element} = lab05:getnth([ ], 2). getnth_2_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"), 3). getnth_3_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"), o). getnth_4_test() -> "there" = lab05:getnth( ["hello", "there"), 2). getnth_5_test() -> "there" = lab05:getnth( ["hello", "there", "where"), 2). getnth_6_test() -> "where" = lab05:getnth( ["hello", "there", "where"), 3). getnth_7_test() -> "where" = lab05:getnth( ["hello", "there", "where", "here"), 3). Function repeat that takes a list of integers and a list of nonnegative integers and returns a list that repeats the integers in the first list according to the numbers indicated by the second list; add the following test cases to the test file these test files also illustrate the logic of repetition to be followed repeat_1_test() -> (2, 2, 2, 2, 3] = lab05:repeat([1, 2, 3), (0, 4, 1]). repeat_2_test() -> [ ] = lab05:repeat( [ ], [0, 4, 1]). repeat_3_test() -> [ ] = lab05:repeat( [1, 2, 3], [ ]). repeat_4_test() -> [4,4] = lab05:repeat( [4,5,6], [2]). 9. In the text editor of your choosing create a file labo5.erl and write function definitions described below - make sure you use the exact same names as indicated in function descriptions. Instead of exporting each function one by one, use command -compile(export_all) at the top of your file that will export all functions together. Download the file labo5_tests.erl, add Erlang unit test library to it, and as you work on your solutions, write unit tests for your functions (unit tests for the first three functions are provided in the test file and for the last 2 functions in this description - note that copying and pasting from the description may introduce invisible characters in which case it is better to re-type the tests). 1. Function money that that takes two tuples, where each tuple represents a money object (each tuple consists of 2 values: dollars and cents) and calculates and returns a new tuple that constitutes the addition of the incoming money objects (dollars + dollars, cents + cents). Assume valid positive integers will be passed and do NOT error check. Normalize the values, i.e. if the cents addition results in a value > 99, adjust dollars and cents properly (hint: to pattern match a function on a tuple consisting of 2 elements, you can use function Name ( {x, Y}) -> ... type of a syntax) 2. Function isolder that takes two dates (each date is a 3-int tuple dd, mm, yyyy) and evaluates to true or false. It evaluates to true if the first argument is a date that comes before the second argument (e.g. 30/3/2012 comes before 1/4/2012, hence a person born on 30/3/2012 is older). (If two dates are the same, the result is false.). Assume the user of your function will enter valid input. Think about how you can use relational operators on entire tuples to simplify processing instead of writing nested ifs 3. Function find Ceiling that takes a list of numbers and returns the modified list constructed by applying the function ceiling to each incoming list element. For example, if original list contains (1.9, 2.1, 3.5), then the resulting list will contain (2.0, 3.0, 4.0]; you are NOT allowed to use ++ or built-in functions or list comprehension (you should use the cons operator to build the new list; you are allowed to use math:ceil though) 4. Function myMin that takes a list and returns its minimum value - use tail recursion to find list minimum and return an atom empty_list if a list is empty; you are NOT allowed to use built-in functions; add appropriate test cases to the test file that use assertEqual macro 5. Function remove Div3 that takes a list of numbers and returns the original list with all values divisible by 3 removed, e.g. if the original list contains [0, 1, 2, -3, 6], then [1, 2] is returned; you are NOT allowed to use built-in functions or list comprehension; add appropriate test cases to the test file that use true matching pattern (i.e. the other method that does NOT use assertEqual) 6. Function calculateBill that takes a list of tuples, where a tuple is of the form name, price, tax_rate, and returns a list of tuples, where each tuple is of the form name, total, 7. Function generate takes three ints as arguments and generates a list of integers from arg1 to arg2 (inclusive) in increments indicated by arg3, e.g. if arg1 = 3, arg2 = 8, and arg 3 = 2, then the function returns [3, 5, 7). If arg1 > arg2, returns an empty list; assume arg3 will be a valid number; you are NOT allowed to use built-in functions or list comprehension; add appropriate test cases to the test file 8. Function getnth that takes a list and an int n and returns the nth element of the list, where the head of the list is the 1st element. You are only allowed to use list functions hd and tl in your solution - no other built-in functions are allowed. If the list is empty or n is invalid, return a tuple: {error, no_such_element} add the following test cases to the test file: getnth_1_test() -> {error, no_such_element} = lab05:getnth([ ], 2). getnth_2_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"), 3). getnth_3_test() -> {error, no_such_element} = lab05:getnth( ["hello", "there"), o). getnth_4_test() -> "there" = lab05:getnth( ["hello", "there"), 2). getnth_5_test() -> "there" = lab05:getnth( ["hello", "there", "where"), 2). getnth_6_test() -> "where" = lab05:getnth( ["hello", "there", "where"), 3). getnth_7_test() -> "where" = lab05:getnth( ["hello", "there", "where", "here"), 3). Function repeat that takes a list of integers and a list of nonnegative integers and returns a list that repeats the integers in the first list according to the numbers indicated by the second list; add the following test cases to the test file these test files also illustrate the logic of repetition to be followed repeat_1_test() -> (2, 2, 2, 2, 3] = lab05:repeat([1, 2, 3), (0, 4, 1]). repeat_2_test() -> [ ] = lab05:repeat( [ ], [0, 4, 1]). repeat_3_test() -> [ ] = lab05:repeat( [1, 2, 3], [ ]). repeat_4_test() -> [4,4] = lab05:repeat( [4,5,6], [2]). 9Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started