-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
language: ruby | ||
rvm: | ||
- 2.2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
task default: %w[test] | ||
|
||
task :test do | ||
ruby "snapr_test.rb" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "zlib" | ||
|
||
class SnaprMessage | ||
|
||
attr_accessor :message | ||
|
||
def initialize(message) | ||
@message = message | ||
end | ||
|
||
def encode_to_ascii | ||
Zlib::Deflate.deflate(@message) | ||
end | ||
|
||
def self.decode_from_ascii(encoded_string) | ||
SnaprMessage.new Zlib::Inflate.inflate(encoded_string) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require 'test/unit' | ||
require_relative 'snapr_message' | ||
|
||
class SnaprMessageTest < Test::Unit::TestCase | ||
|
||
def test_message | ||
msg = SnaprMessage.new("Hello") | ||
assert_equal("Hello", msg.message) | ||
end | ||
|
||
def test_encoding | ||
msg = SnaprMessage.new("Hello") | ||
expected = "x\x9C\xF3H\xCD\xC9\xC9\a\x00\x05\x8C\x01\xF5".force_encoding('ASCII-8BIT') | ||
assert_equal(expected, msg.encode_to_ascii) | ||
end | ||
|
||
def test_decoding | ||
data = "x\x9C\xF3H\xCD\xC9\xC9\a\x00\x05\x8C\x01\xF5".force_encoding('ASCII-8BIT') | ||
msg = SnaprMessage.decode_from_ascii(data) | ||
assert_equal("Hello", msg.message) | ||
end | ||
end |