algorithms/matrix_transpose_comprehensive.rb

tests/_examples/algorithms/matrix_transpose_comprehensive.rb in the metorex repository.

# Test transpose with various cases

# 1. Basic transpose (2x3 matrix)
matrix1 = [[1, 2, 3], [4, 5, 6]]
result1 = matrix1.transpose
puts "Basic 2x3 matrix:"
puts result1

# 2. Transpose a transposed matrix (should give original)
matrix2 = [[1, 2], [3, 4], [5, 6]]
result2 = matrix2.transpose.transpose
puts "Double transpose (3x2 matrix):"
puts result2

# 3. Single row matrix
matrix3 = [[1, 2, 3, 4]]
result3 = matrix3.transpose
puts "Single row matrix:"
puts result3

# 4. Single column matrix
matrix4 = [[1], [2], [3]]
result4 = matrix4.transpose
puts "Single column matrix:"
puts result4

# 5. Square matrix
matrix5 = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
result5 = matrix5.transpose
puts "Square 3x3 matrix:"
puts result5

Output:

Basic 2x3 matrix:
1
4
2
5
3
6
Double transpose (3x2 matrix):
1
2
3
4
5
6
Single row matrix:
1
2
3
4
Single column matrix:
1
2
3
Square 3x3 matrix:
1
4
7
2
5
8
3
6
9