avoiding hard coding of knowledge of algorithm in tests?

I have a package of code which is suppose to tell me where to allocate elements. When I add a new element it may require repositioning of existing elements to keep my ‘tree’ in a format that promises a log-n search. Ultimately when I hand it a current system and new elements to add I should get a list of where to add new elements, and when/where old elements were moved to.

I want to test that the set returned is valid, but I’m not certain how to. I can easily test if the elements are placed in valid locations, ie locations that won’t break assumptions about my ‘tree’, but this doesn’t ensure that I did the minimal and most efficent movement of elements. However, I can’t think of how to check the moves are efficent without essentially rewriting a large part of the package just to test it’s results.

Since I wrote the package I know some implementation specific details. I know that A will be moved to B because I know exactly what logic was used to decide the move, but this is implementation specific. There are cases where I hae multuple equally valid choices and I pick one way when I could pick another. Is it ‘right’ to do this sort of functional testing by utilizing my understanding of the algorithm to specify specifially what should have moved where? if not how else would I write the test to have any idea that i’m not making the most inefficent, but valid, moves possible?

It sounds like you’re looking to make sure that:

  1. Your interface is valid
  2. Your implementation is efficient
  3. You’re not regressing

Valid interface

Write tests which verify that, for each interface method, the result is a valid one, and leave it at that. If you’re expecting a valid list of locations as an output from a function, check that’s what you’re getting back. If you’re expecting certain inputs to cause exceptions or raise errors, test that. Etc…


Efficient Implementation

You must have some sort of measure of efficiency which you’re using to make sure that your solutions are, indeed, the most efficient possible. Sounds like “number of moves”, in your case.

So, manually create some inputs, for which you manually check that the number of moves is optimal. Then, run the inputs through your algorithm, and check that the number of moves it produces exactly your expectations (maybe also check that the solution is valid, for sanity’s sake). If the number is higher, something is wrong with your algorithm; if the number is lower, something is wrong with your hand-math 😉

Ie, provide a list of inputs and an appropriate, expected measurement of efficiency.

Design the inputs to stress corner cases for any general solution to your problem – inputs for which it’s particularly difficult to come up with efficient solutions, or for which your algorithm might break (and continue executing infinitely, for example).


Regression

Generate/find/obtain a set of real-life reflecting inputs for your algorithm.

Run the algorithm against the inputs.

Record and store valid measurements for the results (measurements from the Efficient Implementation section, and others which are likely not to be dependent on your specific algorithm.

Write tests which make sure that each run of your algorithm on the real data, produces valid results, which exactly match the measurements of know, stable, previous runs.

It sounds like your tests need to cover two things:

  1. The API of your package – how the outside world will use it
  2. Internal details of your package – making sure that the current implementation works correctly

So I would write tests in both areas, and divide them up so that their purpose is clear. For example, separate classes, namespaces or packages. If you change the implementation, the first set of tests should be unaffected, ensuring your API is unbroken.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật