-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_better_shapes.R
51 lines (41 loc) · 1.04 KB
/
test_better_shapes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Import testing library and file with functions to test
library(tinytest)
source('better_shapes.R')
# Testing entire process() function
shapes <- "firstshape: circle (r=3)
secondshape: square (l=5)
bluerect: rectangle (l=8,w=2)
secondsquare: square (l=1)
redrect: rectangle (l=45,w=100)"
actual_output <- process(shapes)
expected_output <- read.table(text ="name, type, area
firstshape, circle, 28.27433
secondshape, square, 25
bluerect, rectangle, 16
secondsquare, square, 1
redrect, rectangle, 4500", sep = ',', header=TRUE)
expect_equal(actual_output$area, expected_output$area, tolerance = .0001)
# Test parsing part only
expect_equal(
parse_shape_definition_line("redrect: rectangle (l=45,w=100)"),
list(
shape_name = 'redrect',
shape_type='rectangle',
params = list(
l = 45,
w = 100
)
)
)
expect_equal(
parse_shape_definition_line("firsttriangleever: triangle (a=2, b=3, c=3)"),
list(
shape_name = 'firsttriangleever',
shape_type='triangle',
params = list(
a=2,
b=3,
c=3
)
)
)