Run Rubocop autocorrect on spec/extensions
This commit is contained in:
		
							parent
							
								
									c7b9c83f37
								
							
						
					
					
						commit
						b85e2ef932
					
				@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Copyright (C) 2024 Manuel Bustillo
 | 
					# Copyright (C) 2024 Manuel Bustillo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require 'rails_helper'
 | 
					require 'rails_helper'
 | 
				
			||||||
@ -5,66 +7,66 @@ require 'rails_helper'
 | 
				
			|||||||
module Tree
 | 
					module Tree
 | 
				
			||||||
  RSpec.describe TreeNode do
 | 
					  RSpec.describe TreeNode do
 | 
				
			||||||
    describe '#distance_to_common_ancestor' do
 | 
					    describe '#distance_to_common_ancestor' do
 | 
				
			||||||
      def assert_distance(node_1, node_2, distance)
 | 
					      def assert_distance(node1, node2, distance)
 | 
				
			||||||
        aggregate_failures do
 | 
					        aggregate_failures do
 | 
				
			||||||
          expect(node_1.distance_to_common_ancestor(node_2)).to eq(distance)
 | 
					          expect(node1.distance_to_common_ancestor(node2)).to eq(distance)
 | 
				
			||||||
          expect(node_2.distance_to_common_ancestor(node_1)).to eq(distance)
 | 
					          expect(node2.distance_to_common_ancestor(node1)).to eq(distance)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
      context 'when the two nodes are the same' do
 | 
					      context 'when the two nodes are the same' do
 | 
				
			||||||
        it 'returns 0 when comparing the root itself' do
 | 
					        it 'returns 0 when comparing the root itself' do
 | 
				
			||||||
          root = Tree::TreeNode.new('root')
 | 
					          root = described_class.new('root')
 | 
				
			||||||
          assert_distance(root, root, 0)
 | 
					          assert_distance(root, root, 0)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        it 'returns 0 when comparing a child to itself' do
 | 
					        it 'returns 0 when comparing a child to itself' do
 | 
				
			||||||
          root = Tree::TreeNode.new('root')
 | 
					          root = described_class.new('root')
 | 
				
			||||||
          child = root << Tree::TreeNode.new('child')
 | 
					          child = root << described_class.new('child')
 | 
				
			||||||
          assert_distance(child, child, 0)
 | 
					          assert_distance(child, child, 0)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      context 'when the two nodes are siblings' do
 | 
					      context 'when the two nodes are siblings' do
 | 
				
			||||||
        it 'returns 1 when comparing siblings' do
 | 
					        it 'returns 1 when comparing siblings' do
 | 
				
			||||||
          root = Tree::TreeNode.new('root')
 | 
					          root = described_class.new('root')
 | 
				
			||||||
          child1 = root << Tree::TreeNode.new('child1')
 | 
					          child1 = root << described_class.new('child1')
 | 
				
			||||||
          child2 = root << Tree::TreeNode.new('child2')
 | 
					          child2 = root << described_class.new('child2')
 | 
				
			||||||
          assert_distance(child1, child2, 1)
 | 
					          assert_distance(child1, child2, 1)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      context 'when one node is parent of the other' do
 | 
					      context 'when one node is parent of the other' do
 | 
				
			||||||
        it 'returns 1 when comparing parent to child' do
 | 
					        it 'returns 1 when comparing parent to child' do
 | 
				
			||||||
          root = Tree::TreeNode.new('root')
 | 
					          root = described_class.new('root')
 | 
				
			||||||
          child = root << Tree::TreeNode.new('child')
 | 
					          child = root << described_class.new('child')
 | 
				
			||||||
          assert_distance(root, child, 1)
 | 
					          assert_distance(root, child, 1)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      context 'when one node is grandparent of the other' do
 | 
					      context 'when one node is grandparent of the other' do
 | 
				
			||||||
        it 'returns 2 when comparing grandparent to grandchild' do
 | 
					        it 'returns 2 when comparing grandparent to grandchild' do
 | 
				
			||||||
          root = Tree::TreeNode.new('root')
 | 
					          root = described_class.new('root')
 | 
				
			||||||
          child = root << Tree::TreeNode.new('child')
 | 
					          child = root << described_class.new('child')
 | 
				
			||||||
          grandchild = child << Tree::TreeNode.new('grandchild')
 | 
					          grandchild = child << described_class.new('grandchild')
 | 
				
			||||||
          assert_distance(root, grandchild, 2)
 | 
					          assert_distance(root, grandchild, 2)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      context 'when the two nodes are cousins' do
 | 
					      context 'when the two nodes are cousins' do
 | 
				
			||||||
        it 'returns 2 when comparing cousins' do
 | 
					        it 'returns 2 when comparing cousins' do
 | 
				
			||||||
          root = Tree::TreeNode.new('root')
 | 
					          root = described_class.new('root')
 | 
				
			||||||
          child1 = root << Tree::TreeNode.new('child1')
 | 
					          child1 = root << described_class.new('child1')
 | 
				
			||||||
          child2 = root << Tree::TreeNode.new('child2')
 | 
					          child2 = root << described_class.new('child2')
 | 
				
			||||||
          grandchild1 = child1 << Tree::TreeNode.new('grandchild1')
 | 
					          grandchild1 = child1 << described_class.new('grandchild1')
 | 
				
			||||||
          grandchild2 = child2 << Tree::TreeNode.new('grandchild2')
 | 
					          grandchild2 = child2 << described_class.new('grandchild2')
 | 
				
			||||||
          assert_distance(grandchild1, grandchild2, 2)
 | 
					          assert_distance(grandchild1, grandchild2, 2)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      context 'when the two nodes are not related' do
 | 
					      context 'when the two nodes are not related' do
 | 
				
			||||||
        it 'returns nil' do
 | 
					        it 'returns nil' do
 | 
				
			||||||
          root = Tree::TreeNode.new('root')
 | 
					          root = described_class.new('root')
 | 
				
			||||||
          another_root = Tree::TreeNode.new('another_root')
 | 
					          another_root = described_class.new('another_root')
 | 
				
			||||||
          assert_distance(root, another_root, nil)
 | 
					          assert_distance(root, another_root, nil)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user