Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct HSL and HSLA color formatting #768

Merged
merged 2 commits into from
Dec 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 7 additions & 21 deletions lib/faker/color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,17 @@ def rgb_color
@rgb_colors
end

def single_hsl_color
@single_hsla_color = Faker::Base::rand_in_range(0.0, 360.00).round(2)
@single_hsla_color
end

def alpha_channel
@alpha_channel = rand
@alpha_channel
end

def hsl_color
@hsl_colors = []
3.times do
@hsl_colors.push single_hsl_color
end
@hsl_colors
hsl_values = []
hsl_values << (0..360).to_a.sample
2.times { hsl_values << rand.round(2) }
hsl_values
end

def hsla_color
@hsla_colors = []
3.times do
@hsla_colors.push single_hsl_color
end
@hsla_colors.push alpha_channel
@hsla_colors
hsla_values = hsl_color
hsla_values << rand.round(1)
hsla_values
end
end
end
Expand Down
19 changes: 9 additions & 10 deletions test/test_faker_color.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,24 @@ def test_rgb_color
end
end

def test_single_hsl_color
assert @tester.single_hsl_color.between?(0.0, 360.0)
end

def test_hsl_color
@result = @tester.hsl_color
assert @result.length == 3

@result.each do |color|
assert color.between?(0.0, 360.0)
end
assert @result[0].between?(0, 360)
assert @result[0].is_a?(Fixnum)

assert @result[1].between?(0.0, 1.0)
assert @result[2].between?(0.0, 1.0)
end

def test_hsla_color
@result = @tester.hsla_color
assert @result.length == 4

@result.each do |color|
assert color.between?(0.0, 360.0) || color.between?(0.0, 1.0)
end
assert @result[0].between?(0, 360)
assert @result[1].between?(0.0, 1.0)
assert @result[2].between?(0.0, 1.0)
assert @result[3].between?(0.0, 1.0)
end
end