Skip to content

Commit adf0b46

Browse files
authored
Merge pull request #38 from cardmagic/add-bayes-tests
Add test for classifying safari animals
2 parents 6982656 + 5eed7a3 commit adf0b46

File tree

2 files changed

+40
-21
lines changed

2 files changed

+40
-21
lines changed

.github/workflows/ruby.yml

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7+
18
name: Ruby
29

310
on:
411
push:
5-
branches:
6-
- main
12+
branches: [ "master" ]
713
pull_request:
8-
branches:
9-
- main
14+
branches: [ "master" ]
15+
16+
permissions:
17+
contents: read
1018

1119
jobs:
1220
test:
21+
1322
runs-on: ubuntu-latest
1423
strategy:
1524
matrix:
16-
ruby-version: [2.7, 3.1, 3.2, 3.3] # Add the Ruby versions to test against
25+
ruby-version: ['2.7', '3.0', '3.1', '3.2', 'head']
1726

1827
steps:
19-
- name: Checkout code
20-
uses: actions/checkout@v3
21-
22-
- name: Set up Ruby
23-
uses: ruby/setup-ruby@v1
24-
with:
25-
ruby-version: ${{ matrix.ruby-version }}
26-
27-
- name: Install dependencies
28-
run: |
29-
gem install bundler
30-
bundle install
31-
32-
- name: Run tests
33-
run: |
34-
bundle exec rake test
28+
- uses: actions/checkout@v4
29+
- name: Set up Ruby
30+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
32+
# uses: ruby/setup-ruby@v1
33+
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
34+
with:
35+
ruby-version: ${{ matrix.ruby-version }}
36+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37+
- name: Run tests
38+
run: bundle exec rake test

test/bayes/bayesian_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,19 @@ def test_classification
2727
@classifier.train_uninteresting 'here are some bad words, I hate you'
2828
assert_equal 'Uninteresting', @classifier.classify('I hate bad words and you')
2929
end
30+
31+
def test_safari_animals
32+
bayes = Classifier::Bayes.new 'Lion', 'Elephant'
33+
bayes.train_lion 'lion'
34+
bayes.train_lion 'zebra'
35+
bayes.train_elephant 'elephant'
36+
bayes.train_elephant 'trunk'
37+
bayes.train_elephant 'tusk'
38+
39+
assert_equal 'Lion', bayes.classify('zebra')
40+
assert_equal 'Elephant', bayes.classify('trunk')
41+
assert_equal 'Elephant', bayes.classify('tusk')
42+
assert_equal 'Lion', bayes.classify('lion')
43+
assert_equal 'Elephant', bayes.classify('elephant')
44+
end
3045
end

0 commit comments

Comments
 (0)