-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed the byte encoding to use short constant format in some cases,
and added a few test cases
- Loading branch information
1 parent
d92baac
commit 2223dcd
Showing
5 changed files
with
84 additions
and
3 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,2 @@ | ||
--color | ||
--format progress |
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,50 @@ | ||
require 'rspec' | ||
require 'ev3' | ||
|
||
describe EV3::CoreExtensions do | ||
using EV3::CoreExtensions | ||
|
||
describe "#to_ev3_data" do | ||
def short_negative(number) | ||
0b0011_1111 & [number].pack('c').bytes.first | ||
end | ||
|
||
def long_variable_number(number, byte_count) | ||
bytes_to_follow = EV3::CoreExtensions::BYTES_FOLLOWING_ENCODING[byte_count] | ||
byte_conversion = EV3::CoreExtensions::BYTE_CONVERSION[byte_count] | ||
[0b1000_0000 | bytes_to_follow] + [number].pack(byte_conversion).bytes | ||
end | ||
|
||
subject { number.to_ev3_data } | ||
|
||
context "when a small constant" do | ||
let(:number) { 0 } | ||
it { should eql(number) } | ||
end | ||
|
||
context "when a small constant" do | ||
let(:number) { 31 } | ||
it { should eql(number) } | ||
end | ||
|
||
context "when slightly negative" do | ||
let(:number) { -1 } | ||
it { should eql(short_negative(number)) } | ||
end | ||
|
||
context "when slightly negative" do | ||
let(:number) { -32 } | ||
it { should eql(short_negative(number)) } | ||
end | ||
|
||
context "when large" do | ||
let(:number) { 100_000 } | ||
it { should eql(long_variable_number(number, 4)) } | ||
end | ||
|
||
context "when a large negative" do | ||
let(:number) { -100_000 } | ||
it { should eql(long_variable_number(number, 4)) } | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This file was generated by the `rspec --init` command. Conventionally, all | ||
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. | ||
# Require this file using `require "spec_helper"` to ensure that it is only | ||
# loaded once. | ||
# | ||
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration | ||
RSpec.configure do |config| | ||
config.treat_symbols_as_metadata_keys_with_true_values = true | ||
config.run_all_when_everything_filtered = true | ||
config.filter_run :focus | ||
|
||
# Run specs in random order to surface order dependencies. If you find an | ||
# order dependency and want to debug it, you can fix the order by providing | ||
# the seed, which is printed after each run. | ||
# --seed 1234 | ||
config.order = 'random' | ||
end |