Skip to content

Commit

Permalink
Made mocks more believable. Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcloutier committed Mar 12, 2016
1 parent 7409eef commit 9bd6c23
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
15 changes: 6 additions & 9 deletions lib/ev3/body/mock/mock_color_sensor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,23 @@ defmodule Ev3.Mock.ColorSensor do
end

def nudge_color(value, previous_value) do
if previous_value == nil or :random.uniform(4) == 1 do
if previous_value == nil or :random.uniform(10) == 1 do
value
else
previous_value
end
end


def ambient_light(sensor) do
value = :random.uniform(5)
value = :random.uniform(10) - 5
{value, sensor}
end

def nudge_ambient_light(_value, nil) do
:random.uniform(101) - 1
end

def nudge_ambient_light(value, previous_value) do
IO.puts("Value = #{value}, Previous = #{previous_value}")
(previous_value + value) |> max(0) |> min(100)
case previous_value do
nil -> 30 + :random.uniform(10)
_ -> (previous_value + value) |> max(0) |> min(100)
end
end

def reflected_light(sensor) do
Expand Down
16 changes: 6 additions & 10 deletions lib/ev3/body/mock/mock_infrared_sensor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,21 @@ defmodule Ev3.Mock.InfraredSensor do
end

defp nudge_heading(_channel, value, previous_value) do
case previous_value do
nil -> 25 - :random.uniform(50)
_ -> value + previous_value |> max(-25) |> min(25)
if previous_value == nil or :random.uniform(10) == 1 do
25 - :random.uniform(50)
else
value + previous_value |> max(-25) |> min(25)
end
end

defp seek_distance(sensor, _channel) do
value =
if :random.uniform(2) == 2 do
:random.uniform(101) - 1
else
-128
end
value = :random.uniform(10) - 7
{value, sensor}
end

defp nudge_distance(_channel, value, previous_value) do
case previous_value do
nil -> :random.uniform(101) - 1
nil -> 50 + :random.uniform(50)
_ -> value + previous_value |> max(0) |> min(100)
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ev3/body/mock/mock_touch_sensor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Ev3.Mock.TouchSensor do
{value, sensor}
end

def nudge(_sensor, _sense, previous_value, value) do
def nudge(_sensor, _sense, value, previous_value) do
case previous_value do
nil -> value
_ ->
Expand Down

0 comments on commit 9bd6c23

Please sign in to comment.