5 kyu

Vector Class

124 of 871Detry322
Description
Loading description...
Fundamentals
Object-oriented Programming
  • Please sign in or sign up to leave a comment.
  • Szymon83 Avatar

    Can data be transferred as numbers or a list?

  • hobovsky Avatar

    This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/121.
    Please join the discussion to help us identify duplicate kata and retire them.

  • kmadl Avatar

    Really nice initiation and practice to those unfamiliar with class construction. Thanks for the kata!

  • Paliacho Avatar

    I am stuck in this challenge. Would be really grateful if someone can direct me. Having these errors Expected: #<Vector:0x000056332da9c0c0 @coordinates=[1, 2, 3]>, instead got: #<Vector:0x000056332da9c1b0 @coordinates=[1, 2, 3]> from the creation test and Expected: #<Vector:0x000056332da92a98 @coordinates=[0, 0, 0]>, instead got: #<Vector:0x000056332da92b60 @coordinates=[0, 0, 0]> Expected: #<Vector:0x000056332da92598 @coordinates=[2, 4, 6]>, instead got: #<Vector:0x000056332da92688 @coordinates=[2, 4, 6]> from the addition & subtraction tests I know the objects id's does not match but I am creating a new object on both methods

  • Murf Avatar

    Description of the kata did not state that a tuple can be passed as an argument however in the random test, a tuple was passed instead of a list. Vector([a,b,c]) # creates a new Vector from the supplied 3D array. Vector(a,b,c) # same as above

  • CloudSurfer Avatar

    The tests for my solution pass except for exit... curious if this is an issue with the test (code in python):

    Traceback (most recent call last): File "main.py", line 19, in test.assert_approx_equals(Vector(examples[0]).magnitude, 3.741, 0.001) File "/runner/frameworks/python/cw-2.py", line 84, in assert_approx_equals div = max(abs(actual), abs(expected), 1) TypeError: bad operand type for abs(): 'method'

  • rocketman4321 Avatar

    I'm fairly new to Python OO programming, but is it advisable to access class variables directly? My understanding was to use "getter" functions, but that does not work here for v.x, v.y, v.z, and v.magnitude (v is the Vector) as they're specified and tested without function brackets (e.g,, v.x() )

  • user5329419 Avatar

    Learned about Python Operator Overloading because of the kata.Thank you @Detry322!!!

  • josephpcowell Avatar

    I have passed all tests except for the magnitude test and am getting the error shown below. My magnitude function works in my personal test, but the error seems to have an issue with the test input. Can anyone provide some insight?

    Traceback (most recent call last): File "/runner/frameworks/python/cw-2.py", line 111, in wrapper func() File "main.py", line 104, in _ test.assert_approx_equals(Vector(examples[0][:]).magnitude, 3.741, 0.001) File "/runner/frameworks/python/cw-2.py", line 84, in assert_approx_equals div = max(abs(actual), abs(expected), 1) TypeError: bad operand type for abs(): 'method'

  • dvdr1029 Avatar

    I pass almost all the random tests but I get 14 errors. I think it all stems from the first error saying that both initializatoins should result in the same vector, what am I doing wrong? In my side IDE when I define a vector with a list, tuple, or just 3 inputs they all show the same in the IDE

  • lonkaan Avatar

    Description says Vector([a,b,c]) # creates a new Vector from the supplied 3D array. Vector(a,b,c) # same as above However, test case also gives a Vector((a,b,c)). Maybe point this out in the description?

  • arifcode1 Avatar

    there is error in python test test.assert_approx_equals(Vector(examples[0]).magnitude, 3.741) shoud be test.assert_approx_equals(Vector(examples[0]).magnitude(), 3.741) please fix it in all tests

  • atulprakash1 Avatar

    getting errors like -

    37989 should equal -37989

    there are several of them. the error is not very descriptive. Any one knows which case it may be trying to test?

    the test cases for getting individual items (eg. a.x) is working fine.

  • kupns-aka-kupa Avatar

    There is a problem with random testing taking attributes x and z. Example:

    # random vector = <-80170, -145420, -67903>
    
    # test vector.x 
    -80170 should equal -67903
    
    # vector still <-80170, -145420, -67903>
    # test vector.y
    Test Passed
    
    # vector still <-80170, -145420, -67903>
    # test vector.z
    -67903 should equal -80170
    

    there are always 20 of them. although the rest of the tests for obtaining the attributes x and z have been successfully passed

  • king_nothin Avatar

    This comment has been hidden.

  • anter69 Avatar

    Python: error messages are not clear:

    Basic tests
     Both initializiations should result in the same vector
    <1, 2, 3> should equal <1, 2, 3>
     Should correctly display coordinates (3 of 3 Assertions)
     Should correctly calculate magnitude
     Should handle array representation
     Should handle string representation
     Should handle addition
    <5, 7, 9> should equal <5, 7, 9>
     Should handle subtraction
    <-6, -6, -6> should equal <-6, -6, -6>
    
  • lechevalier Avatar

    This comment has been hidden.

  • dolamroth Avatar

    Magnitude tests should use assert_approx_equals, otherwise this happens:

    444.83565465426 should equal 444.835654654263

  • Blind4Basics Avatar

    This comment has been hidden.

  • Blind4Basics Avatar

    This comment has been hidden.

  • FArekkusu Avatar

    No sample tests.

  • David Gildour Avatar
  • David Gildour Avatar

    Ok, what am I missing? Tests fail upon first addition attempt:

    Testing addition and subtraction
    <6, 8, 7> + <-6, -8, -7> = <0, 0, 0>
    

    The result is what my implementation is returning, and - to my understanding - this is the right thing to expect. Why is it failing then?

  • Voile Avatar

    This comment has been hidden.

  • Voile Avatar

    Needs random tests. And Test.expect should never be used.

  • Meridianbot Avatar

    I think it would be better to change the parameters for the following lines from a,b,c to x,y,z because those aren't vectors.

    a.to_s # returns a string representation of the vector in the form "<a, b, c>" Vector.new([a,b,c]) # creates a Vector from the supplied 3D array. Vector.new(a,b,c) # same as above

  • user578387 Avatar

    Could you either explain better the functions required in a vector or point us to a suitably informative article on these constructs in the description?

  • JoshBrodieNZ Avatar

    "Test::Error: Value is not what was expected" is not a sufficient error message for this kata.