<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Georg Becker</title>
    <description>The latest articles on DEV Community by Georg Becker (@shellrider).</description>
    <link>https://dev.to/shellrider</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3319149%2F5dc4c2d3-5069-4bd9-bde3-2818ee948e84.png</url>
      <title>DEV Community: Georg Becker</title>
      <link>https://dev.to/shellrider</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shellrider"/>
    <language>en</language>
    <item>
      <title>Test your MiniScript code!</title>
      <dc:creator>Georg Becker</dc:creator>
      <pubDate>Sat, 20 Sep 2025 12:48:50 +0000</pubDate>
      <link>https://dev.to/shellrider/test-your-miniscript-code-5ac6</link>
      <guid>https://dev.to/shellrider/test-your-miniscript-code-5ac6</guid>
      <description>&lt;p&gt;Writing tests early and testing your code helps you catch bugs and ensure your code does what you think it does. MiniScript offers a way to do that. The QA module.&lt;/p&gt;

&lt;p&gt;In this short blog I want to show you how I use MiniScript's QA module (&lt;a href="https://miniscript.org/wiki/QA" rel="noopener noreferrer"&gt;https://miniscript.org/wiki/QA&lt;/a&gt;) to test my MiniScript projects. I will do so by going through a very small toy example which covers the basics of my TDD workflow.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 1: Importing the QA module
&lt;/h1&gt;

&lt;p&gt;Whenever I want to to test code I write I import the QA module at the top of my file. QA is a system module so there isn't anything you need to install extra, it should already be provided by your MiniScript distribution. To do this just make sure that your first line reads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "qa"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives me access to useful and important functions such as &lt;code&gt;assert&lt;/code&gt; and &lt;code&gt;assertEqual&lt;/code&gt;, which form the basis of my testing.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 2: Write a test
&lt;/h1&gt;

&lt;p&gt;Yes, before I write a line of code I write a test. I will not argue for or against this strategy here, I just will say that often when working I have great success writing my tests first. In my toy example I will implement a simple function that adds 2 numbers. To organise my test I put them in a function that I call &lt;code&gt;runUnitTests&lt;/code&gt;, in bigger projects I will then call my test functions in this function but for now we can write all the tests inside this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;runUnitTests = function
    print "Starting tests..."
    qa.assert add(1,1) == 2, "Test add 1,1 results in 2"
end function

runUnitTests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Step 3: Run the test
&lt;/h1&gt;

&lt;p&gt;Running the file will now result in an error: &lt;code&gt;Runtime Error: Undefined Identifier: 'add' is unknown in this context [line 5]&lt;/code&gt;. The error message clearly states that we did not implement add yet. This is expected as indeed we did not implement the function yet but we confirmed that our test is running as expected.&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 4: Fix the error
&lt;/h1&gt;

&lt;p&gt;In the next step I will fix the error. While in reality I can of course go a little bit faster, for this explanation I will just fix the error that &lt;code&gt;add&lt;/code&gt; does not exist in the current context by creating an empty function with the arguments I intend to pass like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add = function(a,b)

end function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we run the script again we now see the test executed and failing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Starting tests...
Assert failed: Test function add results in 2 for input a=1 and b=1
Call stack:
  0. (current program) line 9
  1. (current program) line 12
(To clear this display, enter: qa.clear)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This now tells me that my assertion failed and that add 1,1 did not return something equal to 2. I can easily fix this by having add return 2. This is a temporary step. I want to show you that using TDD it is a viable strategy to go for the simplest solution first and discover a full solution by adding more tests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add = function(a,b)
    return 2
end function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running the script now will work. Amazing our code is tested!&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 5: Write more tests
&lt;/h1&gt;

&lt;p&gt;The attentive reader will have spotted, that the solution right now is indeed still rubbish. With the very limited toy example it is very clear to spot what the problem is but you would be surprised how often you can encounter cases that are basically the same as what I produced right now in the wild. Right now we have code that works and is even 100% tested but  of course actually it only works for 1 test case. Let's fix this by adding another test case:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;runUnitTests = function
    print "Starting tests..."
    qa.assert add(1,1) == 2, "Test function add results in 2 for input a=1 and b=1"
    qa.assert add(2,3) == 5, "Test function add results in 5 for input a=2 and b=3"
end function

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When we run our tests now it results in the following output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Starting tests...
Assert failed: Test function add results in 5 for input a=2 and b=3
Call stack:
  0. (current program) line 10
  1. (current program) line 13
(To clear this display, enter: qa.clear)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let us fix this by actually implementing the function. I will change the &lt;code&gt;add&lt;/code&gt; function to read as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;add = function(a,b)
    return a + b
end function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running the script now everything works.&lt;/p&gt;

&lt;h1&gt;
  
  
  Put the testing inside if locals == globals
&lt;/h1&gt;

&lt;p&gt;Very often the approach illustrated here is very useful when developing modules we want other people to be able to use in their projects. To allow them to use our module but also run our tests it is customary to put the unit tests inside an &lt;code&gt;if locals == globals&lt;/code&gt; statement. Joe Strout already explained this pattern in an excellent blog here:&lt;a href="https://dev.to/joestrout/if-locals-globals-38bh"&gt;https://dev.to/joestrout/if-locals-globals-38bh&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So to do this in our code we simply put the function call to &lt;code&gt;runUnitTests&lt;/code&gt; into the statement. This ensures that the tests are only ran when the module is executed directly and not when it is imported. Here the full code of our newly developed and tested add module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "qa"

add = function(a,b)
    return a + b
end function

runUnitTests = function
print "Starting tests..."
    qa.assert add(1,1) == 2, "Test function add results in 2 for input a=1 and b=1"
    qa.assert add(2,3) == 5, "Test function add results in 5 for input a=2 and b=3"
end function

if locals == globals then runUnitTests
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This of course is a very small toy example but if you practice the techniques outlined here it can allow you to write MiniScript using a TDD approach and help you deliver tested and less buggy modules. I encourage you to give this workflow a try in your next project!&lt;/p&gt;

</description>
      <category>programming</category>
      <category>miniscript</category>
      <category>testing</category>
    </item>
    <item>
      <title>9-slicing for Mini Micro</title>
      <dc:creator>Georg Becker</dc:creator>
      <pubDate>Thu, 03 Jul 2025 13:05:22 +0000</pubDate>
      <link>https://dev.to/shellrider/9-slicing-for-mini-micro-2mck</link>
      <guid>https://dev.to/shellrider/9-slicing-for-mini-micro-2mck</guid>
      <description>&lt;p&gt;&lt;strong&gt;TLDR&lt;/strong&gt; Here is code to show how 9-slicing can be done in Mini Micro: &lt;a href="https://github.com/shellrider-games/ms-Image9Slice" rel="noopener noreferrer"&gt;https://github.com/shellrider-games/ms-Image9Slice&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When creating game UIs a feature I need pretty regularly is 9-slicing. 9 slicing is a technique used to resize images that aims to prevent distortions due to scaling by ensuring that the image corners do not scale and only the middle part of an image is resized. It may sound a little unintuitive. Why we would want that behaviour? But it is a concept best understood through a visual explanation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1zvex8jk3thr7m9ben9o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1zvex8jk3thr7m9ben9o.png" alt="Image description" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This works by cutting the source image into 9 different parts and scaling the individual pieces differently. The 4 corners are not scaled (1, 3, 7, 9), the border pieces are either scaled vertically (4, 6) or horizontally (2, 8), and the middle part is scaled in both directions (5).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnmsjjcwlkxcaireprqo9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnmsjjcwlkxcaireprqo9.png" alt="Image description" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;del&gt;Mini Micro does not provide this functionality out of the box&lt;/del&gt; (Well I was wrong there, actually there is an &lt;code&gt;Image9Slice&lt;/code&gt; class in &lt;code&gt;/sys/lib/gui&lt;/code&gt;). This gives us the opportunity to implement 9-slicing ourselves and understand the topic even better.&lt;/p&gt;

&lt;p&gt;To solve this in MiniMicro I created a module called &lt;strong&gt;Image9Slice&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Image9Slice = {}
Image9Slice.src = null
Image9Slice.left = 0
Image9Slice.bottom = 0
Image9Slice.right = 0
Image9Slice.top = 0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First thing I did is setup a &lt;code&gt;Image9Slice&lt;/code&gt; class with &lt;em&gt;src&lt;/em&gt;, which represents an &lt;code&gt;Image&lt;/code&gt; object and &lt;em&gt;left&lt;/em&gt;, &lt;em&gt;bottom&lt;/em&gt;, &lt;em&gt;right&lt;/em&gt; and &lt;em&gt;top&lt;/em&gt; for the margins.&lt;br&gt;
I also added a &lt;code&gt;create&lt;/code&gt; function, which allows me to create new instances of my class, kinda like a constructor in other languages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Image9Slice.create = function(src, left, bottom, right, top)
    noob = new Image9Slice
    noob.src = src
    noob.left = left
    noob.bottom = bottom
    noob.right = right
    noob.top = top
    return noob
end function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The final magic happens in the &lt;code&gt;draw&lt;/code&gt; function, in which I use an &lt;code&gt;Image9Slice&lt;/code&gt; object, the position on the screen as &lt;em&gt;left&lt;/em&gt; and &lt;em&gt;bottom&lt;/em&gt;, the &lt;em&gt;width&lt;/em&gt; and &lt;em&gt;height&lt;/em&gt; of the drawn image, a &lt;em&gt;pixelDisplay&lt;/em&gt; which is the display and an optional parameter &lt;em&gt;scale&lt;/em&gt; which allows us to scale the source image. The &lt;em&gt;scale&lt;/em&gt; parameter is very useful in case you want to use  this technique for pixel-art UIs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;draw = function(image, left, bottom, width, height, pixelDisplay, scale=1)
    qa.assert(
      image isa Image9Slice,
      "image must be of type Image9Slice")
    qa.assert(
      pixelDisplay isa Display and pixelDisplay.mode == 3,
      "pixelDisplay must be a PixelDisplay")

    middleHeight = height - image.bottom * scale - image.top * scale
    srcHeight = image.src.height - image.bottom - image.top
    topStop = bottom + height - image.top * scale
    srcTopStop = image.src.height - image.top

    middleWidth = width - image.left * scale - image.right * scale
    srcWidth = image.src.width - image.left - image.right
    rightStop = left + width - image.right * scale
    srcRightStop = image.src.width - image.right

    pixelDisplay.drawImage image.src,
      left, bottom, image.left * scale, image.bottom * scale,
      0, 0, image.left, image.bottom
    pixelDisplay.drawImage image.src,
      left, bottom + image.bottom * scale, image.left * scale, middleHeight,
      0, image.bottom, image.left, srcHeight
    pixelDisplay.drawImage image.src,
      left, topStop, image.left * scale, image.top * scale,
      0, srcTopStop, image.left, image.top

    pixelDisplay.drawImage image.src,
      left + image.left * scale, bottom, middleWidth, image.bottom * scale,
      image.left, 0, srcWidth, image.bottom
    pixelDisplay.drawImage image.src,
      left + image.left * scale, bottom + image.bottom * scale, middleWidth, middleHeight,
      image.left, image.bottom, srcWidth, srcHeight
    pixelDisplay.drawImage image.src,
      left + image.left * scale, topStop, middleWidth, image.top * scale,
      image.left, srcTopStop, srcWidth, image.top

    pixelDisplay.drawImage image.src,
      rightStop, bottom, image.right * scale, image.bottom * scale,
      srcRightStop, 0, image.right, image.bottom
    pixelDisplay.drawImage image.src,
      rightStop, bottom + image.bottom * scale, image.right * scale, middleHeight,
      srcRightStop, image.bottom, image.right, srcHeight
    pixelDisplay.drawImage image.src,
      rightStop, topStop, image.right * scale, image.top *scale,
      srcRightStop, srcTopStop, image.right, image.top  
end function
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The bulk of the function performs calculations to figure out where on the screen to draw the 9 image slices and which pixels of the source image to use. In my demo code that runs if you clone the repo from Github (&lt;a href="https://github.com/shellrider-games/ms-Image9Slice" rel="noopener noreferrer"&gt;https://github.com/shellrider-games/ms-Image9Slice&lt;/a&gt;), I use this function to draw 2 panels from a 16 x 16 pixel source image upscaled by a factor of 3.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7yxbsr0h2ynwv9ed8bre.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7yxbsr0h2ynwv9ed8bre.png" alt="Image description" width="800" height="623"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope you found this useful and maybe, next time you create an UI you can use 9-slicing as the basis for creating your own custom, reusable widgets.&lt;/p&gt;

</description>
      <category>miniscript</category>
      <category>minimicro</category>
      <category>programming</category>
      <category>gamedev</category>
    </item>
  </channel>
</rss>
