Testing your code

Ok, guys, again I here with question. How do you test your works?

I understand how to test functions and procedures mathematically (for example, generating sine table in memory), but how to check if some general function is ok after you do optimizations or extend functionality?

It does my head go dizzy when it comes to usual functions, like sprite drawing or monsters AI or SMC parts.
And how to test whole program? Are there some ways to get it at least semi-automata?

Yes, code is assembly.
Heavy on the disasm

Comments

  • Your talking about unit testing.
    One way would be to include some test code (only assembled for testing and not in your final release.) which runs through your code and checks various aspects.
    Lets say we want to make sure your positioning of the hero never overflows. Write some code to run through all the possible values of the x position of your hero. Your test code will set the x position for each value (say 0 ~ 256), calls all the code to position and draw your hero, making sure the code always returns without crashing / overflowing etc.

    You'd need to have code for each different type of test / per function. This can be quite large, methodical and boring.

    Of course ultimately the best testing, after unit testing is by playing the game.
    Sod it!

    @luny@mstdn.games
    https://www.luny.co.uk
  • If you have a function which does something invisible like ai
    Create a separate program which prints things to the screen like the path an enemy is going to take and what the monster is thinking,then when it is right just copy and paste to the game,
    When you need to make changes,you can use the separate program and copy n paste again
  • Testing code?
    I wanna tell you a story 'bout a woman I know...
  • Testing code?

    Or any emulator/other tools to help doing this?

    Heavy on the disasm
  • What is this testing code that you speak of? I've never heard of such a thing, ;)
    So far, so meh :)
  • polomint wrote: »
    What is this testing code that you speak of? I've never heard of such a thing, ;)

    So, I'm The One?
    I'm The First?

    ^:)^
    Heavy on the disasm
  • You could also write it in boriels basic first, then convert it to ASM
  • There are things like unit tests or assertions ( https://en.wikipedia.org/wiki/Assertion_(software_development) ) that people use when programming in modern languages. In many professional companies there are probably very elaborated, detailed, corporate procedures how to use them when you write your code.

    Personally when I'm coding for Spectrum I don't do such stuff and don't even know what would be possible. I just write code, I run it and check if it run correctly. If it doesn't, I adjust it and run again until it's allright.

    You start builiding your program from small bricks and at each stage you check if the latest changes work all right.

    For example
    - first try to draw a part of location
    - then try to draw whole location
    - then try to draw a sprite
    - then try to move it over location
    - then draw more sprites
    - then check colisions between them
    - then add score, energy, collected items etc.

    While making a game you test what you added lately. And You need to think of edge cases, predict and check cases when your code may break, for example

    - what if player tries to go out of screen in single screen game
    - what if player presses left and right at same time
    - what if player presses fire when he already fired a bullet
    - may enemy be created everywhere or do we need to avoid creating him in the wall

    Of course when yor game is ready you have to complete it yourself, probably more than once to hunt for bugs that survived to this stage.

    Generally you write, test, write, test, write, test. Never write bigger blocks of code without testing them in the middle.



  • If like me you write code that has a habit of overwriting the wrong areas of memory, and struggle to find the cause sometimes, Zeus has MEM_VAR (read/write), MEM_ROM (read-only), MEM_SMC (read/write) and MEM_VOID (neither) pseudo-ops you can annotate your code with.

    And a Trap On Error tickbox that breaks as soon as you run off the rails.
    Robin Verhagen-Guest
    SevenFFF / Threetwosevensixseven / colonel32
    NXtel NXTP ESP Update ESP Reset CSpect Plugins
  • Ralf wrote: »
    coding for Spectrum I don't do such stuff and don't even know what would be possible. I just write code, I run it and check if it run correctly. If it doesn't, I adjust it and run again until it's allright.

    This is a root of evil, what bothers me.

    At this moment, Luny is right, easier way is to write some side code what does include functions/procedures, and test it separately.
    But anyway it does need a lot of manual work.
    Can Fuse (or any other emulator) can be setup on start to change registers, run given snapshot, then save work?
    Heavy on the disasm
  • edited January 2017
    Testing is usually done by running the program under test through a simulator which can be initialized with cpu state (pc, sp, memory, register values) and then queried for cpu state after the test program has run to determine if the test passed.

    In the z80 world, the only project that does significant testing is sdcc which runs the gcc torture tests to check that the compiler remains correct as it is developed. They use ucsim as z80 simulator and the test programs are in C and compiled by sdcc.

    If your subroutines under test can be verified by looking at cpu state only, you can take a similar approach but if you have to see results with your own eyes (eg as in if the display is correct) you may have to just generate the test programs and manually run each to verify the display is right.

    In the latter case and if you don't have hundreds or thousands of tests to run, you can instead assemble or compile your individual test programs and run each in an emulator individually to verify output.

    What makes testing much more convenient is if you are using tools with linking assemblers. These will allow you to write tests that can extract only the subroutines under test from your project as needed. That way you don't have to worry about running out of memory or having to place routines or data at specific memory addresses.

    It's also much easier to test if you can write the tests in a high level language or script. These will allow you to generate corner case tests automatically and quickly. Yes you can write in asm but it will take you until next year to do it.
    Post edited by Alcoholics Anonymous on
  • English is not my native tongue and I read that question as " How to test your Cod " the answer of course to that question is, using a gill scale system, developed by the Fin's.

    As to the original question, I have no idea.
    Every time I read that the oldest person in the world has died, I have to do a quick check to see it isn't ME..........
  • grey key wrote: »
    English is not my native tongue and I read that question as " How to test your Cod "

    How to test... my God...

    Heavy on the disasm
  • mik3d3nch wrote: »
    Easy! On error print "You screwed up again!"

    And sometimes, based on random numbers print "This is not my fault!" and "Are you crazy to do THIS?!"
    Heavy on the disasm
  • edited January 2017
    The easiest way to determine if your code has bugs is to make sure your software displays your email address somewhere, then publish it. ;)
    Post edited by guesser on
  • guesser wrote: »
    The easiest way to determine if your code has bugs is to make sure your software displays your email address somewhere, then publish it. ;)

    ..you wish. I hardly get any mail. =)
    http://iki.fi/sol | http://iki.fi/sol/speccy/ | https://github.com/jarikomppa/speccy
    http://goo.gl/q2j0NZ - make ZX Spectrum choose your own adventure games, no programming needed (release 3)
  • So, I will ask again.
    When testing procedure I can save work as snapshot, then loop change registers in it by external script, and run emulator.
    But. Can I somehow produce work with emulator (which one?) by retrieving it's state, and send commands from my script (stop and exit on given address, save memory as binary, stop after given amount of time, etc) ?
    Heavy on the disasm
  • edited January 2017
    Following Luny's idea, print values to the console, if the tested value is not expected then pause the emulator and save a snapshot with name including tested value plues brief description. I think Boriel would allow this along with some scripting tool of your choice, remember that you can encapsulate asm code within Boriel, so you may use this Basic tool to make this sort of sneaky/homey/pizza-esque testin' tool
    Post edited by hikoki on
  • I'm not aware of any emulator with "deep" support for external debugging, so you're pretty much limited to what you can accomplish manually or via specific test case code running over individual modules.

    This is probably still light years ahead of what most developers were working with back in the day....
  • I also don't now about external debugging but before you start thinking up such things you should experiment with available options like tracing program execution in debugger and conditional breakpoints.

    From emulators known to me , Spin has the most advanced breakpoint system. Search these forums, there is some very old post explaining it.
  • Thanks all.
    I'm thinking about to tweak DelphiSpec (some time ago it was modified a little to be compilable under Lazarus), and to get useful things from it with extended functionality.
    Heavy on the disasm
Sign In or Register to comment.