File: channel_entropy_spec.rb

package info (click to toggle)
ruby-rmagick 6.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,232 kB
  • sloc: cpp: 19,563; ruby: 17,147; sh: 88; javascript: 36; makefile: 13
file content (41 lines) | stat: -rw-r--r-- 1,182 bytes parent folder | download | duplicates (2)
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
RSpec.describe Magick::Image, '#channel_entropy' do
  pixels = [[45, 9, 156], [45, 98, 156], [45, 74, 156], [45, 196, 156]]

  it 'returns a channel entropy', unsupported_before('6.9.0') do
    image = build_image(pixels: pixels)

    result = image.channel_entropy

    expect(result).to eq([0.3333333333333333])
  end

  it 'returns 0.0 when all pixels are the same', unsupported_before('6.9.0') do
    image = build_image(pixels: pixels)

    result = image.channel_entropy(Magick::RedChannel)

    expect(result).to eq([0.0])
  end

  it 'returns 1.0 when all pixels are different', unsupported_before('6.9.0') do
    image = build_image(pixels: pixels)

    result = image.channel_entropy(Magick::GreenChannel)

    expect(result).to eq([1.0])
  end

  it 'returns the entropy of multiple given channels', unsupported_before('6.9.0') do
    image = build_image(pixels: pixels)

    result = image.channel_entropy(Magick::GreenChannel, Magick::BlueChannel)

    expect(result).to eq([0.5])
  end

  it 'raises an error on earlier versions', supported_before('6.9.0') do
    image = build_image

    expect { image.channel_entropy }.to raise_error(NotImplementedError)
  end
end