PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/plugins/bio-graphics/test/unit/test_creation.rb

https://github.com/phegnal/topfind
Ruby | 77 lines | 67 code | 10 blank | 0 comment | 0 complexity | 76191cc44976ea8d143aed91de19aac4 MD5 | raw file
Possible License(s): GPL-2.0, CC0-1.0, LGPL-2.1, MIT
  1. require 'test/unit'
  2. require File.dirname(__FILE__) + '/../../lib/bio-graphics'
  3. class TestPanel < Test::Unit::TestCase
  4. def test_panel_creation
  5. panel = Bio::Graphics::Panel.new(0..1000, :width => 500, :clickable => false)
  6. assert_equal(1000, panel.length)
  7. assert_equal(500, panel.width)
  8. assert_equal(false, panel.clickable)
  9. assert_equal(0, panel.lend)
  10. assert_equal(1000, panel.rend)
  11. assert_equal(1000/500, panel.rescale_factor)
  12. assert_equal(0, panel.tracks.length)
  13. end
  14. def test_panel_creation_out_of_boundaries
  15. panel = Bio::Graphics::Panel.new(-7..5000, :width => 500, :clickable => false)
  16. assert_same(0, panel.lend)
  17. assert_same(5000, panel.rend)
  18. end
  19. end
  20. class TestTrack < Test::Unit::TestCase
  21. def setup
  22. @panel = Bio::Graphics::Panel.new(0..1000, :width => 500, :clickable => false)
  23. end
  24. def test_track_creation
  25. track = @panel.add_track('test_track', :label => false, :glyph => :generic, :colour => [1,0,0])
  26. assert_equal('test_track', track.name)
  27. assert_equal([1,0,0], track.colour)
  28. assert_equal(:generic, track.glyph)
  29. assert_equal(1, @panel.tracks.length)
  30. assert_equal(0, track.features.length)
  31. end
  32. end
  33. class TestRuler < Test::Unit::TestCase
  34. def test_scaling_factor
  35. panel = Bio::Graphics::Panel.new(0..1000, :width => 600)
  36. ruler = Bio::Graphics::Ruler.new(panel)
  37. assert_equal(1,ruler.scaling_factor(5,1000/600))
  38. assert_equal(2,ruler.scaling_factor(5,1000/500))
  39. assert_equal(1,ruler.scaling_factor(5,500/500))
  40. end
  41. def test_drawing
  42. panel = Bio::Graphics::Panel.new(100..370, :width => 600)
  43. ruler = Bio::Graphics::Ruler.new(panel)
  44. assert_equal(270.0/600.0,panel.rescale_factor)
  45. assert_equal(1,ruler.scaling_factor)
  46. assert_equal(5,ruler.minor_tick_distance)
  47. assert_equal(50,ruler.major_tick_distance)
  48. assert_equal(100,ruler.first_tick_position)
  49. i = 0
  50. ruler.first_tick_position.step(panel.rend, ruler.minor_tick_distance) do |tick|
  51. assert(i*ruler.min_pixels_per_tick,(tick - panel.lend) / panel.rescale_factor)
  52. i += 1
  53. end
  54. end
  55. end
  56. class TestFeature < Test::Unit::TestCase
  57. def setup
  58. @panel = Bio::Graphics::Panel.new(0..1000, :width => 500)
  59. @track = @panel.add_track('test_track', :label => false, :glyph => :generic, :colour => [1,0,0])
  60. end
  61. def test_feature_creation
  62. feature = @track.add_feature(Bio::Feature.new('type', '123..456'), :label => 'test_feature')
  63. assert_equal('test_feature', feature.name)
  64. assert_equal(123, feature.locations[0].from)
  65. assert_equal(456, feature.locations[-1].to)
  66. end
  67. end