lex-agentic-social 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/lex-agentic-social.gemspec +30 -0
- data/lib/legion/extensions/agentic/social/apprenticeship/client.rb +28 -0
- data/lib/legion/extensions/agentic/social/apprenticeship/helpers/apprenticeship.rb +90 -0
- data/lib/legion/extensions/agentic/social/apprenticeship/helpers/apprenticeship_engine.rb +109 -0
- data/lib/legion/extensions/agentic/social/apprenticeship/helpers/apprenticeship_model.rb +93 -0
- data/lib/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship.rb +112 -0
- data/lib/legion/extensions/agentic/social/apprenticeship/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/apprenticeship.rb +19 -0
- data/lib/legion/extensions/agentic/social/conflict/actors/stale_check.rb +45 -0
- data/lib/legion/extensions/agentic/social/conflict/client.rb +27 -0
- data/lib/legion/extensions/agentic/social/conflict/helpers/conflict_log.rb +70 -0
- data/lib/legion/extensions/agentic/social/conflict/helpers/llm_enhancer.rb +130 -0
- data/lib/legion/extensions/agentic/social/conflict/helpers/severity.rb +47 -0
- data/lib/legion/extensions/agentic/social/conflict/runners/conflict.rb +112 -0
- data/lib/legion/extensions/agentic/social/conflict/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/conflict.rb +19 -0
- data/lib/legion/extensions/agentic/social/conscience/client.rb +26 -0
- data/lib/legion/extensions/agentic/social/conscience/helpers/constants.rb +53 -0
- data/lib/legion/extensions/agentic/social/conscience/helpers/moral_evaluator.rb +178 -0
- data/lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb +116 -0
- data/lib/legion/extensions/agentic/social/conscience/runners/conscience.rb +117 -0
- data/lib/legion/extensions/agentic/social/conscience/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/conscience.rb +19 -0
- data/lib/legion/extensions/agentic/social/consent/actors/tier_evaluation.rb +45 -0
- data/lib/legion/extensions/agentic/social/consent/client.rb +27 -0
- data/lib/legion/extensions/agentic/social/consent/helpers/consent_map.rb +199 -0
- data/lib/legion/extensions/agentic/social/consent/helpers/tiers.rb +54 -0
- data/lib/legion/extensions/agentic/social/consent/local_migrations/20260316000010_create_consent_domains.rb +16 -0
- data/lib/legion/extensions/agentic/social/consent/runners/consent.rb +228 -0
- data/lib/legion/extensions/agentic/social/consent/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/consent.rb +25 -0
- data/lib/legion/extensions/agentic/social/entrainment/client.rb +19 -0
- data/lib/legion/extensions/agentic/social/entrainment/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/social/entrainment/helpers/entrainment_engine.rb +120 -0
- data/lib/legion/extensions/agentic/social/entrainment/helpers/pairing.rb +86 -0
- data/lib/legion/extensions/agentic/social/entrainment/runners/cognitive_entrainment.rb +89 -0
- data/lib/legion/extensions/agentic/social/entrainment/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/entrainment.rb +19 -0
- data/lib/legion/extensions/agentic/social/governance/actors/shadow_ai_scan.rb +19 -0
- data/lib/legion/extensions/agentic/social/governance/actors/vote_timeout.rb +45 -0
- data/lib/legion/extensions/agentic/social/governance/client.rb +27 -0
- data/lib/legion/extensions/agentic/social/governance/helpers/layers.rb +40 -0
- data/lib/legion/extensions/agentic/social/governance/helpers/proposal.rb +94 -0
- data/lib/legion/extensions/agentic/social/governance/runners/governance.rb +87 -0
- data/lib/legion/extensions/agentic/social/governance/runners/shadow_ai.rb +93 -0
- data/lib/legion/extensions/agentic/social/governance/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/governance.rb +20 -0
- data/lib/legion/extensions/agentic/social/joint_attention/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/social/joint_attention/client.rb +28 -0
- data/lib/legion/extensions/agentic/social/joint_attention/helpers/attention_target.rb +124 -0
- data/lib/legion/extensions/agentic/social/joint_attention/helpers/constants.rb +34 -0
- data/lib/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager.rb +157 -0
- data/lib/legion/extensions/agentic/social/joint_attention/runners/joint_attention.rb +88 -0
- data/lib/legion/extensions/agentic/social/joint_attention/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/joint_attention.rb +20 -0
- data/lib/legion/extensions/agentic/social/mentalizing/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/social/mentalizing/client.rb +28 -0
- data/lib/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution.rb +58 -0
- data/lib/legion/extensions/agentic/social/mentalizing/helpers/constants.rb +33 -0
- data/lib/legion/extensions/agentic/social/mentalizing/helpers/mental_model.rb +137 -0
- data/lib/legion/extensions/agentic/social/mentalizing/runners/mentalizing.rb +93 -0
- data/lib/legion/extensions/agentic/social/mentalizing/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/mentalizing.rb +20 -0
- data/lib/legion/extensions/agentic/social/mirror/client.rb +33 -0
- data/lib/legion/extensions/agentic/social/mirror/helpers/constants.rb +65 -0
- data/lib/legion/extensions/agentic/social/mirror/helpers/mirror_engine.rb +132 -0
- data/lib/legion/extensions/agentic/social/mirror/helpers/mirror_event.rb +46 -0
- data/lib/legion/extensions/agentic/social/mirror/helpers/simulation.rb +43 -0
- data/lib/legion/extensions/agentic/social/mirror/runners/observe.rb +52 -0
- data/lib/legion/extensions/agentic/social/mirror/runners/resonance.rb +79 -0
- data/lib/legion/extensions/agentic/social/mirror/runners/simulate.rb +63 -0
- data/lib/legion/extensions/agentic/social/mirror/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/mirror.rb +22 -0
- data/lib/legion/extensions/agentic/social/mirror_system/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/social/mirror_system/client.rb +28 -0
- data/lib/legion/extensions/agentic/social/mirror_system/helpers/constants.rb +62 -0
- data/lib/legion/extensions/agentic/social/mirror_system/helpers/mirror_system.rb +162 -0
- data/lib/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior.rb +67 -0
- data/lib/legion/extensions/agentic/social/mirror_system/runners/mirror.rb +99 -0
- data/lib/legion/extensions/agentic/social/mirror_system/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/mirror_system.rb +20 -0
- data/lib/legion/extensions/agentic/social/moral_reasoning/client.rb +19 -0
- data/lib/legion/extensions/agentic/social/moral_reasoning/helpers/constants.rb +49 -0
- data/lib/legion/extensions/agentic/social/moral_reasoning/helpers/dilemma.rb +68 -0
- data/lib/legion/extensions/agentic/social/moral_reasoning/helpers/llm_enhancer.rb +140 -0
- data/lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_engine.rb +239 -0
- data/lib/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation.rb +45 -0
- data/lib/legion/extensions/agentic/social/moral_reasoning/runners/moral_reasoning.rb +121 -0
- data/lib/legion/extensions/agentic/social/moral_reasoning/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/moral_reasoning.rb +21 -0
- data/lib/legion/extensions/agentic/social/perspective_shifting/client.rb +29 -0
- data/lib/legion/extensions/agentic/social/perspective_shifting/helpers/constants.rb +67 -0
- data/lib/legion/extensions/agentic/social/perspective_shifting/helpers/perspective.rb +45 -0
- data/lib/legion/extensions/agentic/social/perspective_shifting/helpers/perspective_view.rb +57 -0
- data/lib/legion/extensions/agentic/social/perspective_shifting/helpers/shifting_engine.rb +166 -0
- data/lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb +167 -0
- data/lib/legion/extensions/agentic/social/perspective_shifting/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/perspective_shifting.rb +20 -0
- data/lib/legion/extensions/agentic/social/social/client.rb +25 -0
- data/lib/legion/extensions/agentic/social/social/helpers/constants.rb +84 -0
- data/lib/legion/extensions/agentic/social/social/helpers/social_graph.rb +172 -0
- data/lib/legion/extensions/agentic/social/social/runners/social.rb +146 -0
- data/lib/legion/extensions/agentic/social/social/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/social.rb +18 -0
- data/lib/legion/extensions/agentic/social/social_learning/client.rb +25 -0
- data/lib/legion/extensions/agentic/social/social_learning/helpers/constants.rb +42 -0
- data/lib/legion/extensions/agentic/social/social_learning/helpers/model_agent.rb +82 -0
- data/lib/legion/extensions/agentic/social/social_learning/helpers/observed_behavior.rb +61 -0
- data/lib/legion/extensions/agentic/social/social_learning/helpers/social_learning_engine.rb +134 -0
- data/lib/legion/extensions/agentic/social/social_learning/runners/social_learning.rb +105 -0
- data/lib/legion/extensions/agentic/social/social_learning/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/social_learning.rb +20 -0
- data/lib/legion/extensions/agentic/social/symbiosis/client.rb +23 -0
- data/lib/legion/extensions/agentic/social/symbiosis/helpers/constants.rb +50 -0
- data/lib/legion/extensions/agentic/social/symbiosis/helpers/ecosystem.rb +113 -0
- data/lib/legion/extensions/agentic/social/symbiosis/helpers/symbiosis_engine.rb +104 -0
- data/lib/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond.rb +112 -0
- data/lib/legion/extensions/agentic/social/symbiosis/runners/cognitive_symbiosis.rb +101 -0
- data/lib/legion/extensions/agentic/social/symbiosis/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/symbiosis.rb +22 -0
- data/lib/legion/extensions/agentic/social/theory_of_mind/client.rb +26 -0
- data/lib/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model.rb +173 -0
- data/lib/legion/extensions/agentic/social/theory_of_mind/helpers/constants.rb +70 -0
- data/lib/legion/extensions/agentic/social/theory_of_mind/helpers/mental_state_tracker.rb +169 -0
- data/lib/legion/extensions/agentic/social/theory_of_mind/runners/theory_of_mind.rb +159 -0
- data/lib/legion/extensions/agentic/social/theory_of_mind/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/theory_of_mind.rb +19 -0
- data/lib/legion/extensions/agentic/social/trust/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/social/trust/client.rb +27 -0
- data/lib/legion/extensions/agentic/social/trust/helpers/trust_map.rb +160 -0
- data/lib/legion/extensions/agentic/social/trust/helpers/trust_model.rb +52 -0
- data/lib/legion/extensions/agentic/social/trust/local_migrations/20260316000020_create_trust_entries.rb +23 -0
- data/lib/legion/extensions/agentic/social/trust/runners/trust.rb +80 -0
- data/lib/legion/extensions/agentic/social/trust/version.rb +13 -0
- data/lib/legion/extensions/agentic/social/trust.rb +25 -0
- data/lib/legion/extensions/agentic/social/version.rb +11 -0
- data/lib/legion/extensions/agentic/social.rb +34 -0
- data/spec/legion/extensions/agentic/social/apprenticeship/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/social/apprenticeship/cognitive_apprenticeship_spec.rb +11 -0
- data/spec/legion/extensions/agentic/social/apprenticeship/helpers/apprenticeship_engine_spec.rb +146 -0
- data/spec/legion/extensions/agentic/social/apprenticeship/helpers/apprenticeship_model_spec.rb +124 -0
- data/spec/legion/extensions/agentic/social/apprenticeship/helpers/apprenticeship_spec.rb +136 -0
- data/spec/legion/extensions/agentic/social/apprenticeship/runners/cognitive_apprenticeship_spec.rb +154 -0
- data/spec/legion/extensions/agentic/social/conflict/actors/stale_check_spec.rb +45 -0
- data/spec/legion/extensions/agentic/social/conflict/client_spec.rb +15 -0
- data/spec/legion/extensions/agentic/social/conflict/helpers/conflict_log_spec.rb +232 -0
- data/spec/legion/extensions/agentic/social/conflict/helpers/llm_enhancer_spec.rb +189 -0
- data/spec/legion/extensions/agentic/social/conflict/helpers/severity_spec.rb +215 -0
- data/spec/legion/extensions/agentic/social/conflict/runners/conflict_spec.rb +151 -0
- data/spec/legion/extensions/agentic/social/conscience/client_spec.rb +58 -0
- data/spec/legion/extensions/agentic/social/conscience/helpers/constants_spec.rb +124 -0
- data/spec/legion/extensions/agentic/social/conscience/helpers/moral_evaluator_spec.rb +253 -0
- data/spec/legion/extensions/agentic/social/conscience/helpers/moral_store_spec.rb +230 -0
- data/spec/legion/extensions/agentic/social/conscience/runners/conscience_spec.rb +239 -0
- data/spec/legion/extensions/agentic/social/consent/actors/tier_evaluation_spec.rb +46 -0
- data/spec/legion/extensions/agentic/social/consent/client_spec.rb +33 -0
- data/spec/legion/extensions/agentic/social/consent/helpers/tiers_spec.rb +49 -0
- data/spec/legion/extensions/agentic/social/consent/local_persistence_spec.rb +234 -0
- data/spec/legion/extensions/agentic/social/consent/runners/consent_spec.rb +224 -0
- data/spec/legion/extensions/agentic/social/entrainment/client_spec.rb +21 -0
- data/spec/legion/extensions/agentic/social/entrainment/helpers/entrainment_engine_spec.rb +116 -0
- data/spec/legion/extensions/agentic/social/entrainment/helpers/pairing_spec.rb +103 -0
- data/spec/legion/extensions/agentic/social/entrainment/runners/cognitive_entrainment_spec.rb +87 -0
- data/spec/legion/extensions/agentic/social/governance/actors/vote_timeout_spec.rb +45 -0
- data/spec/legion/extensions/agentic/social/governance/client_spec.rb +14 -0
- data/spec/legion/extensions/agentic/social/governance/helpers/layers_spec.rb +190 -0
- data/spec/legion/extensions/agentic/social/governance/helpers/proposal_spec.rb +188 -0
- data/spec/legion/extensions/agentic/social/governance/runners/governance_spec.rb +101 -0
- data/spec/legion/extensions/agentic/social/governance/runners/shadow_ai_spec.rb +65 -0
- data/spec/legion/extensions/agentic/social/joint_attention/client_spec.rb +36 -0
- data/spec/legion/extensions/agentic/social/joint_attention/helpers/attention_target_spec.rb +258 -0
- data/spec/legion/extensions/agentic/social/joint_attention/helpers/joint_focus_manager_spec.rb +238 -0
- data/spec/legion/extensions/agentic/social/joint_attention/runners/joint_attention_spec.rb +228 -0
- data/spec/legion/extensions/agentic/social/mentalizing/client_spec.rb +19 -0
- data/spec/legion/extensions/agentic/social/mentalizing/helpers/belief_attribution_spec.rb +108 -0
- data/spec/legion/extensions/agentic/social/mentalizing/helpers/mental_model_spec.rb +179 -0
- data/spec/legion/extensions/agentic/social/mentalizing/runners/mentalizing_spec.rb +162 -0
- data/spec/legion/extensions/agentic/social/mirror/client_spec.rb +92 -0
- data/spec/legion/extensions/agentic/social/mirror/helpers/constants_spec.rb +123 -0
- data/spec/legion/extensions/agentic/social/mirror/helpers/mirror_engine_spec.rb +217 -0
- data/spec/legion/extensions/agentic/social/mirror/helpers/mirror_event_spec.rb +102 -0
- data/spec/legion/extensions/agentic/social/mirror/helpers/simulation_spec.rb +100 -0
- data/spec/legion/extensions/agentic/social/mirror/runners/observe_spec.rb +77 -0
- data/spec/legion/extensions/agentic/social/mirror/runners/resonance_spec.rb +123 -0
- data/spec/legion/extensions/agentic/social/mirror/runners/simulate_spec.rb +103 -0
- data/spec/legion/extensions/agentic/social/mirror_system/client_spec.rb +40 -0
- data/spec/legion/extensions/agentic/social/mirror_system/helpers/mirror_system_spec.rb +144 -0
- data/spec/legion/extensions/agentic/social/mirror_system/helpers/observed_behavior_spec.rb +98 -0
- data/spec/legion/extensions/agentic/social/mirror_system/runners/mirror_spec.rb +122 -0
- data/spec/legion/extensions/agentic/social/moral_reasoning/client_spec.rb +34 -0
- data/spec/legion/extensions/agentic/social/moral_reasoning/helpers/dilemma_spec.rb +108 -0
- data/spec/legion/extensions/agentic/social/moral_reasoning/helpers/llm_enhancer_spec.rb +232 -0
- data/spec/legion/extensions/agentic/social/moral_reasoning/helpers/moral_engine_spec.rb +266 -0
- data/spec/legion/extensions/agentic/social/moral_reasoning/helpers/moral_foundation_spec.rb +70 -0
- data/spec/legion/extensions/agentic/social/moral_reasoning/runners/moral_reasoning_spec.rb +275 -0
- data/spec/legion/extensions/agentic/social/perspective_shifting/client_spec.rb +30 -0
- data/spec/legion/extensions/agentic/social/perspective_shifting/helpers/constants_spec.rb +99 -0
- data/spec/legion/extensions/agentic/social/perspective_shifting/helpers/perspective_spec.rb +77 -0
- data/spec/legion/extensions/agentic/social/perspective_shifting/helpers/perspective_view_spec.rb +105 -0
- data/spec/legion/extensions/agentic/social/perspective_shifting/helpers/shifting_engine_spec.rb +246 -0
- data/spec/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting_spec.rb +277 -0
- data/spec/legion/extensions/agentic/social/social/client_spec.rb +72 -0
- data/spec/legion/extensions/agentic/social/social/helpers/constants_spec.rb +99 -0
- data/spec/legion/extensions/agentic/social/social/helpers/social_graph_spec.rb +322 -0
- data/spec/legion/extensions/agentic/social/social/runners/social_spec.rb +220 -0
- data/spec/legion/extensions/agentic/social/social_learning/client_spec.rb +25 -0
- data/spec/legion/extensions/agentic/social/social_learning/helpers/constants_spec.rb +44 -0
- data/spec/legion/extensions/agentic/social/social_learning/helpers/model_agent_spec.rb +120 -0
- data/spec/legion/extensions/agentic/social/social_learning/helpers/observed_behavior_spec.rb +81 -0
- data/spec/legion/extensions/agentic/social/social_learning/helpers/social_learning_engine_spec.rb +196 -0
- data/spec/legion/extensions/agentic/social/social_learning/runners/social_learning_spec.rb +150 -0
- data/spec/legion/extensions/agentic/social/symbiosis/client_spec.rb +45 -0
- data/spec/legion/extensions/agentic/social/symbiosis/helpers/constants_spec.rb +73 -0
- data/spec/legion/extensions/agentic/social/symbiosis/helpers/ecosystem_spec.rb +185 -0
- data/spec/legion/extensions/agentic/social/symbiosis/helpers/symbiosis_engine_spec.rb +182 -0
- data/spec/legion/extensions/agentic/social/symbiosis/helpers/symbiotic_bond_spec.rb +209 -0
- data/spec/legion/extensions/agentic/social/symbiosis/runners/cognitive_symbiosis_spec.rb +182 -0
- data/spec/legion/extensions/agentic/social/theory_of_mind/client_spec.rb +63 -0
- data/spec/legion/extensions/agentic/social/theory_of_mind/helpers/agent_model_spec.rb +244 -0
- data/spec/legion/extensions/agentic/social/theory_of_mind/helpers/constants_spec.rb +71 -0
- data/spec/legion/extensions/agentic/social/theory_of_mind/helpers/mental_state_tracker_spec.rb +228 -0
- data/spec/legion/extensions/agentic/social/theory_of_mind/runners/theory_of_mind_spec.rb +221 -0
- data/spec/legion/extensions/agentic/social/trust/actors/decay_spec.rb +62 -0
- data/spec/legion/extensions/agentic/social/trust/client_spec.rb +17 -0
- data/spec/legion/extensions/agentic/social/trust/helpers/trust_map_spec.rb +299 -0
- data/spec/legion/extensions/agentic/social/trust/helpers/trust_model_spec.rb +179 -0
- data/spec/legion/extensions/agentic/social/trust/local_persistence_spec.rb +359 -0
- data/spec/legion/extensions/agentic/social/trust/runners/trust_spec.rb +84 -0
- data/spec/spec_helper.rb +54 -0
- metadata +319 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Social::Trust::Helpers::TrustMap do
|
|
6
|
+
subject(:map) { described_class.new }
|
|
7
|
+
|
|
8
|
+
let(:agent_id) { 'agent-001' }
|
|
9
|
+
|
|
10
|
+
describe '#initialize' do
|
|
11
|
+
it 'starts with an empty entries hash' do
|
|
12
|
+
expect(map.entries).to eq({})
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe '#get' do
|
|
17
|
+
it 'returns nil for an unknown agent' do
|
|
18
|
+
expect(map.get(agent_id)).to be_nil
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'returns nil for a known agent in a different domain' do
|
|
22
|
+
map.get_or_create(agent_id, domain: :code)
|
|
23
|
+
expect(map.get(agent_id, domain: :ops)).to be_nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it 'returns the entry after it has been created' do
|
|
27
|
+
map.get_or_create(agent_id)
|
|
28
|
+
expect(map.get(agent_id)).not_to be_nil
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'retrieves an entry for the correct domain' do
|
|
32
|
+
map.get_or_create(agent_id, domain: :code)
|
|
33
|
+
entry = map.get(agent_id, domain: :code)
|
|
34
|
+
expect(entry[:domain]).to eq(:code)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'defaults domain to :general' do
|
|
38
|
+
map.get_or_create(agent_id)
|
|
39
|
+
entry = map.get(agent_id)
|
|
40
|
+
expect(entry[:domain]).to eq(:general)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe '#get_or_create' do
|
|
45
|
+
it 'creates a new entry for a new agent' do
|
|
46
|
+
entry = map.get_or_create(agent_id)
|
|
47
|
+
expect(entry).not_to be_nil
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'returns the same entry on subsequent calls' do
|
|
51
|
+
first = map.get_or_create(agent_id)
|
|
52
|
+
second = map.get_or_create(agent_id)
|
|
53
|
+
expect(first).to equal(second)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'initializes composite to NEUTRAL_TRUST' do
|
|
57
|
+
entry = map.get_or_create(agent_id)
|
|
58
|
+
expect(entry[:composite]).to eq(Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::NEUTRAL_TRUST)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'creates independent entries per domain' do
|
|
62
|
+
general = map.get_or_create(agent_id, domain: :general)
|
|
63
|
+
code = map.get_or_create(agent_id, domain: :code)
|
|
64
|
+
expect(general).not_to equal(code)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'creates independent entries per agent' do
|
|
68
|
+
a = map.get_or_create('agent-a')
|
|
69
|
+
b = map.get_or_create('agent-b')
|
|
70
|
+
expect(a).not_to equal(b)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
describe '#record_interaction' do
|
|
75
|
+
context 'with a positive interaction' do
|
|
76
|
+
it 'increments interaction_count by 1' do
|
|
77
|
+
map.record_interaction(agent_id, positive: true)
|
|
78
|
+
expect(map.get(agent_id)[:interaction_count]).to eq(1)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'increments positive_count by 1' do
|
|
82
|
+
map.record_interaction(agent_id, positive: true)
|
|
83
|
+
expect(map.get(agent_id)[:positive_count]).to eq(1)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'does not increment negative_count' do
|
|
87
|
+
map.record_interaction(agent_id, positive: true)
|
|
88
|
+
expect(map.get(agent_id)[:negative_count]).to eq(0)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'increases all dimension values above NEUTRAL_TRUST' do
|
|
92
|
+
map.record_interaction(agent_id, positive: true)
|
|
93
|
+
entry = map.get(agent_id)
|
|
94
|
+
Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::TRUST_DIMENSIONS.each do |dim|
|
|
95
|
+
expect(entry[:dimensions][dim]).to be > Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::NEUTRAL_TRUST
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'increases composite above NEUTRAL_TRUST' do
|
|
100
|
+
map.record_interaction(agent_id, positive: true)
|
|
101
|
+
expect(map.get(agent_id)[:composite]).to be > Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::NEUTRAL_TRUST
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'sets last_interaction to a recent time' do
|
|
105
|
+
before = Time.now.utc
|
|
106
|
+
map.record_interaction(agent_id, positive: true)
|
|
107
|
+
expect(map.get(agent_id)[:last_interaction]).to be >= before
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
context 'with a negative interaction' do
|
|
112
|
+
it 'increments interaction_count by 1' do
|
|
113
|
+
map.record_interaction(agent_id, positive: false)
|
|
114
|
+
expect(map.get(agent_id)[:interaction_count]).to eq(1)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it 'increments negative_count by 1' do
|
|
118
|
+
map.record_interaction(agent_id, positive: false)
|
|
119
|
+
expect(map.get(agent_id)[:negative_count]).to eq(1)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
it 'does not increment positive_count' do
|
|
123
|
+
map.record_interaction(agent_id, positive: false)
|
|
124
|
+
expect(map.get(agent_id)[:positive_count]).to eq(0)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it 'decreases composite below NEUTRAL_TRUST' do
|
|
128
|
+
map.record_interaction(agent_id, positive: false)
|
|
129
|
+
expect(map.get(agent_id)[:composite]).to be < Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::NEUTRAL_TRUST
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it 'applies the asymmetric penalty (penalty > reinforcement)' do
|
|
133
|
+
map.record_interaction(agent_id, positive: true)
|
|
134
|
+
positive_composite = map.get(agent_id)[:composite]
|
|
135
|
+
map2 = described_class.new
|
|
136
|
+
map2.record_interaction(agent_id, positive: false)
|
|
137
|
+
negative_composite = map2.get(agent_id)[:composite]
|
|
138
|
+
delta_positive = positive_composite - Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::NEUTRAL_TRUST
|
|
139
|
+
delta_negative = Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::NEUTRAL_TRUST - negative_composite
|
|
140
|
+
expect(delta_negative).to be > delta_positive
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
it 'creates the entry if it does not exist' do
|
|
145
|
+
map.record_interaction('new-agent', positive: true)
|
|
146
|
+
expect(map.get('new-agent')).not_to be_nil
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'tracks trust separately per domain' do
|
|
150
|
+
map.record_interaction(agent_id, positive: true, domain: :code)
|
|
151
|
+
map.record_interaction(agent_id, positive: false, domain: :ops)
|
|
152
|
+
expect(map.get(agent_id, domain: :code)[:composite]).to be > map.get(agent_id, domain: :ops)[:composite]
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
describe '#reinforce_dimension' do
|
|
157
|
+
it 'increases the targeted dimension' do
|
|
158
|
+
map.get_or_create(agent_id)
|
|
159
|
+
map.reinforce_dimension(agent_id, dimension: :competence, amount: 0.2)
|
|
160
|
+
entry = map.get(agent_id)
|
|
161
|
+
expect(entry[:dimensions][:competence]).to be > Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::NEUTRAL_TRUST
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
it 'does not change non-targeted dimensions' do
|
|
165
|
+
map.get_or_create(agent_id)
|
|
166
|
+
map.reinforce_dimension(agent_id, dimension: :competence, amount: 0.1)
|
|
167
|
+
entry = map.get(agent_id)
|
|
168
|
+
expect(entry[:dimensions][:reliability]).to eq(Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::NEUTRAL_TRUST)
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
it 'updates composite after reinforcement' do
|
|
172
|
+
map.get_or_create(agent_id)
|
|
173
|
+
original_composite = map.get(agent_id)[:composite]
|
|
174
|
+
map.reinforce_dimension(agent_id, dimension: :competence, amount: 0.2)
|
|
175
|
+
expect(map.get(agent_id)[:composite]).to be > original_composite
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
it 'ignores an invalid dimension' do
|
|
179
|
+
map.get_or_create(agent_id)
|
|
180
|
+
original = map.get(agent_id)[:composite]
|
|
181
|
+
map.reinforce_dimension(agent_id, dimension: :invalid_dim)
|
|
182
|
+
expect(map.get(agent_id)[:composite]).to eq(original)
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
it 'clamps dimension to 1.0 maximum' do
|
|
186
|
+
map.get_or_create(agent_id)
|
|
187
|
+
map.reinforce_dimension(agent_id, dimension: :reliability, amount: 5.0)
|
|
188
|
+
expect(map.get(agent_id)[:dimensions][:reliability]).to eq(1.0)
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
describe '#decay_all' do
|
|
193
|
+
it 'returns 0 when no entries exist' do
|
|
194
|
+
expect(map.decay_all).to eq(0)
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it 'returns the number of entries decayed' do
|
|
198
|
+
map.get_or_create('agent-a')
|
|
199
|
+
map.get_or_create('agent-b')
|
|
200
|
+
expect(map.decay_all).to eq(2)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
it 'reduces each dimension by TRUST_DECAY_RATE' do
|
|
204
|
+
map.get_or_create(agent_id)
|
|
205
|
+
map.decay_all
|
|
206
|
+
entry = map.get(agent_id)
|
|
207
|
+
Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::TRUST_DIMENSIONS.each do |dim|
|
|
208
|
+
expected = Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::NEUTRAL_TRUST -
|
|
209
|
+
Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::TRUST_DECAY_RATE
|
|
210
|
+
expect(entry[:dimensions][dim]).to be_within(0.0001).of(expected)
|
|
211
|
+
end
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
it 'floors dimensions at 0.0 when trust is already near-zero' do
|
|
215
|
+
map.get_or_create(agent_id)
|
|
216
|
+
200.times { map.decay_all }
|
|
217
|
+
entry = map.get(agent_id)
|
|
218
|
+
Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::TRUST_DIMENSIONS.each do |dim|
|
|
219
|
+
expect(entry[:dimensions][dim]).to eq(0.0)
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it 'recomputes composite after decay' do
|
|
224
|
+
map.get_or_create(agent_id)
|
|
225
|
+
before = map.get(agent_id)[:composite]
|
|
226
|
+
map.decay_all
|
|
227
|
+
expect(map.get(agent_id)[:composite]).to be < before
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
describe '#trusted_agents' do
|
|
232
|
+
it 'returns empty array when no entries exist' do
|
|
233
|
+
expect(map.trusted_agents).to be_empty
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
it 'returns entries with composite >= min_trust' do
|
|
237
|
+
5.times { map.record_interaction(agent_id, positive: true) }
|
|
238
|
+
result = map.trusted_agents
|
|
239
|
+
expect(result).not_to be_empty
|
|
240
|
+
result.each do |entry|
|
|
241
|
+
expect(entry[:composite]).to be >= Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel::TRUST_CONSIDER_THRESHOLD
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it 'excludes entries below min_trust' do
|
|
246
|
+
map.record_interaction(agent_id, positive: false)
|
|
247
|
+
expect(map.trusted_agents).to be_empty
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
it 'filters by domain' do
|
|
251
|
+
5.times { map.record_interaction(agent_id, positive: true, domain: :code) }
|
|
252
|
+
map.record_interaction('other-agent', positive: true, domain: :ops)
|
|
253
|
+
result = map.trusted_agents(domain: :code)
|
|
254
|
+
expect(result.all? { |e| e[:domain] == :code }).to be true
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
it 'sorts by composite descending' do
|
|
258
|
+
5.times { map.record_interaction('agent-high', positive: true) }
|
|
259
|
+
3.times { map.record_interaction('agent-low', positive: true) }
|
|
260
|
+
result = map.trusted_agents
|
|
261
|
+
composites = result.map { |e| e[:composite] }
|
|
262
|
+
expect(composites).to eq(composites.sort.reverse)
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it 'accepts a custom min_trust threshold' do
|
|
266
|
+
5.times { map.record_interaction(agent_id, positive: true) }
|
|
267
|
+
strict_result = map.trusted_agents(min_trust: 0.9)
|
|
268
|
+
loose_result = map.trusted_agents(min_trust: 0.3)
|
|
269
|
+
expect(strict_result.size).to be <= loose_result.size
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
273
|
+
describe '#delegatable_agents' do
|
|
274
|
+
it 'requires TRUST_DELEGATE_THRESHOLD (higher than trusted_agents default)' do
|
|
275
|
+
5.times { map.record_interaction(agent_id, positive: true) }
|
|
276
|
+
trusted = map.trusted_agents.size
|
|
277
|
+
delegatable = map.delegatable_agents.size
|
|
278
|
+
expect(delegatable).to be <= trusted
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
it 'returns empty array when no entries meet the delegation threshold' do
|
|
282
|
+
map.record_interaction(agent_id, positive: true)
|
|
283
|
+
expect(map.delegatable_agents).to be_empty
|
|
284
|
+
end
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
describe '#count' do
|
|
288
|
+
it 'returns 0 for an empty map' do
|
|
289
|
+
expect(map.count).to eq(0)
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
it 'counts total entries across all agents and domains' do
|
|
293
|
+
map.get_or_create('a', domain: :general)
|
|
294
|
+
map.get_or_create('a', domain: :code)
|
|
295
|
+
map.get_or_create('b', domain: :general)
|
|
296
|
+
expect(map.count).to eq(3)
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
RSpec.describe Legion::Extensions::Agentic::Social::Trust::Helpers::TrustModel do
|
|
6
|
+
describe 'TRUST_DIMENSIONS' do
|
|
7
|
+
it 'is a frozen array of symbols' do
|
|
8
|
+
expect(described_class::TRUST_DIMENSIONS).to be_a(Array)
|
|
9
|
+
expect(described_class::TRUST_DIMENSIONS).to be_frozen
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'contains exactly four dimensions' do
|
|
13
|
+
expect(described_class::TRUST_DIMENSIONS.size).to eq(4)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'includes reliability' do
|
|
17
|
+
expect(described_class::TRUST_DIMENSIONS).to include(:reliability)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'includes competence' do
|
|
21
|
+
expect(described_class::TRUST_DIMENSIONS).to include(:competence)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it 'includes integrity' do
|
|
25
|
+
expect(described_class::TRUST_DIMENSIONS).to include(:integrity)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'includes benevolence' do
|
|
29
|
+
expect(described_class::TRUST_DIMENSIONS).to include(:benevolence)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
describe 'threshold constants' do
|
|
34
|
+
it 'TRUST_CONSIDER_THRESHOLD is 0.3' do
|
|
35
|
+
expect(described_class::TRUST_CONSIDER_THRESHOLD).to eq(0.3)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'TRUST_DELEGATE_THRESHOLD is 0.7' do
|
|
39
|
+
expect(described_class::TRUST_DELEGATE_THRESHOLD).to eq(0.7)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'delegate threshold is higher than consider threshold' do
|
|
43
|
+
expect(described_class::TRUST_DELEGATE_THRESHOLD).to be > described_class::TRUST_CONSIDER_THRESHOLD
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'TRUST_DECAY_RATE is 0.005' do
|
|
47
|
+
expect(described_class::TRUST_DECAY_RATE).to eq(0.005)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'TRUST_REINFORCEMENT is 0.05' do
|
|
51
|
+
expect(described_class::TRUST_REINFORCEMENT).to eq(0.05)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'TRUST_PENALTY is 0.15' do
|
|
55
|
+
expect(described_class::TRUST_PENALTY).to eq(0.15)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'penalty is asymmetrically larger than reinforcement' do
|
|
59
|
+
expect(described_class::TRUST_PENALTY).to be > described_class::TRUST_REINFORCEMENT
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
it 'NEUTRAL_TRUST is 0.3' do
|
|
63
|
+
expect(described_class::NEUTRAL_TRUST).to eq(0.3)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'NEUTRAL_TRUST equals TRUST_CONSIDER_THRESHOLD (new agents are borderline trustworthy)' do
|
|
67
|
+
expect(described_class::NEUTRAL_TRUST).to eq(described_class::TRUST_CONSIDER_THRESHOLD)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
describe '.new_trust_entry' do
|
|
72
|
+
let(:entry) { described_class.new_trust_entry(agent_id: 'agent-42') }
|
|
73
|
+
|
|
74
|
+
it 'sets agent_id' do
|
|
75
|
+
expect(entry[:agent_id]).to eq('agent-42')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'defaults domain to :general' do
|
|
79
|
+
expect(entry[:domain]).to eq(:general)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'respects a custom domain' do
|
|
83
|
+
custom = described_class.new_trust_entry(agent_id: 'agent-1', domain: :code)
|
|
84
|
+
expect(custom[:domain]).to eq(:code)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'initializes all four dimensions to NEUTRAL_TRUST' do
|
|
88
|
+
described_class::TRUST_DIMENSIONS.each do |dim|
|
|
89
|
+
expect(entry[:dimensions][dim]).to eq(described_class::NEUTRAL_TRUST)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it 'sets composite to NEUTRAL_TRUST' do
|
|
94
|
+
expect(entry[:composite]).to eq(described_class::NEUTRAL_TRUST)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'starts with zero interaction_count' do
|
|
98
|
+
expect(entry[:interaction_count]).to eq(0)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it 'starts with zero positive_count' do
|
|
102
|
+
expect(entry[:positive_count]).to eq(0)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'starts with zero negative_count' do
|
|
106
|
+
expect(entry[:negative_count]).to eq(0)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it 'sets last_interaction to nil' do
|
|
110
|
+
expect(entry[:last_interaction]).to be_nil
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it 'sets created_at to a recent UTC time' do
|
|
114
|
+
before = Time.now.utc
|
|
115
|
+
e = described_class.new_trust_entry(agent_id: 'x')
|
|
116
|
+
expect(e[:created_at]).to be >= before
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it 'returns a different hash for each call' do
|
|
120
|
+
a = described_class.new_trust_entry(agent_id: 'a')
|
|
121
|
+
b = described_class.new_trust_entry(agent_id: 'b')
|
|
122
|
+
expect(a).not_to equal(b)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
describe '.composite_score' do
|
|
127
|
+
it 'returns the arithmetic mean of dimension values' do
|
|
128
|
+
dims = { reliability: 0.8, competence: 0.6, integrity: 0.4, benevolence: 0.2 }
|
|
129
|
+
expect(described_class.composite_score(dims)).to be_within(0.0001).of(0.5)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
it 'returns 1.0 when all dimensions are 1.0' do
|
|
133
|
+
dims = described_class::TRUST_DIMENSIONS.to_h { |d| [d, 1.0] }
|
|
134
|
+
expect(described_class.composite_score(dims)).to eq(1.0)
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it 'returns 0.0 when all dimensions are 0.0' do
|
|
138
|
+
dims = described_class::TRUST_DIMENSIONS.to_h { |d| [d, 0.0] }
|
|
139
|
+
expect(described_class.composite_score(dims)).to eq(0.0)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
it 'returns NEUTRAL_TRUST for freshly initialized dimensions' do
|
|
143
|
+
dims = described_class::TRUST_DIMENSIONS.to_h { |d| [d, described_class::NEUTRAL_TRUST] }
|
|
144
|
+
expect(described_class.composite_score(dims)).to eq(described_class::NEUTRAL_TRUST)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'returns 0.0 for an empty dimensions hash' do
|
|
148
|
+
expect(described_class.composite_score({})).to eq(0.0)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
describe '.clamp' do
|
|
153
|
+
it 'returns the value when within range' do
|
|
154
|
+
expect(described_class.clamp(0.5)).to eq(0.5)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
it 'clamps to 0.0 when value is negative' do
|
|
158
|
+
expect(described_class.clamp(-0.1)).to eq(0.0)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
it 'clamps to 1.0 when value exceeds 1.0' do
|
|
162
|
+
expect(described_class.clamp(1.5)).to eq(1.0)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
it 'returns exactly 0.0 at the lower boundary' do
|
|
166
|
+
expect(described_class.clamp(0.0)).to eq(0.0)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it 'returns exactly 1.0 at the upper boundary' do
|
|
170
|
+
expect(described_class.clamp(1.0)).to eq(1.0)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it 'accepts custom min/max bounds' do
|
|
174
|
+
expect(described_class.clamp(5.0, 0.0, 10.0)).to eq(5.0)
|
|
175
|
+
expect(described_class.clamp(15.0, 0.0, 10.0)).to eq(10.0)
|
|
176
|
+
expect(described_class.clamp(-1.0, 0.0, 10.0)).to eq(0.0)
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|