Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/usr/local/ruby -w
  2. # -*- coding: utf-8 -*-
  3. require "test/unit"
  4.  
  5. class TestString < Test::Unit::TestCase
  6.  
  7. #将字符串按指定的字符分割为数组
  8. def test_split
  9. test_str = "ABC DEF HIJ KLM NOP"
  10. assert_equal(["ABC", "DEF", "HIJ", "KLM", "NOP"], test_str.split(" "))
  11. end
  12.  
  13. # 去除指定的重复字符
  14. def test_squeeze
  15. assert_equal("ABCA", "ABCAAA".squeeze!("A"))
  16. assert_nil("ABCABC".squeeze!("A"))
  17. assert_nil("ABCABC".squeeze!("ABC"))
  18. assert_nil("ABCA A".squeeze!("A"))
  19. end
  20.  
  21. #根据给定的正则表达式将字符串切分为字符数组
  22. def test_scan
  23. test_str = "123A456B789C0"
  24. assert_equal(["123", "456", "789", "0"], test_str.scan(/\d+/))
  25. end
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement