Recommended unit testing setup
What is the recommended way to write and run unit tests in Ada? Which test library and test runner? Does Alire run the tests (alr test
does not seem to do it)?
1 post - 1 participant
What is the recommended way to write and run unit tests in Ada? Which test library and test runner? Does Alire run the tests (alr test
does not seem to do it)?
1 post - 1 participant
SweetAda (https://www.sweetada.org) got another step of functionality in the high-side of computing and successfully boots on an (QEMU™-emulated) PowerPC 64-bit POWER8 (R) platform.
The support is minimal, but it is able to startup from CPU reset and can do output on a terminal console.
Standby for future improvements.
1 post - 1 participant
Didn’t see a thread for this yet, so figured I would start one. I’ve only worked on part 1. I did like that I could come up with various methods of doing this right off the bat. I decided on spoiler.
5 posts - 3 participants
While working on day 6 of AoC, I found myself breaking a larger calculation into parts and saving them as constants in the declarative region of the function. This was super clean for reading and let me document all my steps nicely. I also knew that if any of the steps failed, then my result should be 0. So I figured I would put an exception handler in the function and return 0 (Note that the case where exceptions happen would be pretty rare based on some really edge case inputs that weren’t practical to the problem):
The problem I ran into is if the early steps raised an exception, then the exception handler wouldn’t catch them as they were in the declarative region. See mock up below:
function Calculate(Inputs : Input_Type) return Integer is
Step_1 : constant Integer := Some_Function(Stuff);
Step_2 : constant Integer := Some_Other_Function(Stuff);
begin
return Final_Function(Step_1, Step_2);
exception
when others => return 0; -- doesn't catch Step_1 or Step_2 exceptions!!!
end Calculate;
Any suggestions on a clean way to catch those declarative exceptions? I don’t like putting them in a declare block in the function body because that just indents everything needlessly. Currently I renamed my original function to old_name_unhandled and call it a new wrapper function named the original name, but that does feel kinda silly.
I was hoping there is an aspect or pragma maybe?
6 posts - 5 participants
@JeremyGrosser hasn’t posted on today’s puzzle yet; I hope he won’t mind if I do.
There’s always at least one puzzle with ginormous numbers, though I don’t recall their appearance in as early as Day 5!
The first speed bump I encountered is that gnat defaults (?) to 32-bit integers for Natural
, so my machine choked, though nearly 12 hours later I can’t remember whether it choked on the input proper or during the tracing. Very well, then: spoiler
Is 32-bits a fixed standard for Ada’s Natural
? Since 64-bit numbers are not uncommon in these puzzles (at least 2 or 3 puzzles will go there), should I by default define a numeric type and use that? (Isn’t that arguably the Ada way anyway? I’ve always wished the puzzle master would be more specific about the data we might encounter in these puzzles.)
The second speed bump is that solving Part 2 the natural, “brute-force” way takes the computer while, and I mean a while. It is doable! It took my machine “only” about 15 minutes. (I’ve paid for those gigahertz; might as well use them, right?)
So, while I was able to solve Part 2 via brute force – not usually possible when we start to see 6-digit numbers, let alone 9-digit ones! – I decided to spoiler.
My solution is here. I’d be interested to know if anyone took a different approach.
17 posts - 5 participants
svd2ada generates volatile arrays.
e.g. IMR_MR_Field_Array
There are two other options that I believe will work easily with spark. The .Val Hal.UInt32 or a record of booleans with different names instead of the array.
The array makes for simpler code. So before I switch to the value. Could anyone suggest how the Spark compatibility error may be avoided. Editing the svds isn’t ideal but possible. A function or procedure local instantiation would be ideal. Any ideas?
IMR1.MR.Arr(Var) := True;
error: volatile object cannot appear in this context. Spark RM 7.1.3 (10).
Thanks
2 posts - 1 participant
I got stuck on silly parsing bugs in part 1 and am too tired for part 2 tonight. Looks like it’s gonna be spoiler
9 posts - 5 participants
Hi everyone,
I’ve been a long time lurker on the Ada subreddit and was directed here by Lucretia to share my plan/idea. After a few years in Python and short, unhappy tread through the chaos of C++, I’m learning Ada, while I’m still new to the language, I have a project idea. I want to make sure I don’t reinvent the wheel and that I engage with anyone else who is interested.
Are you familiar with OpenCV? If not, it’s a very good computer vision library in C++ and Python.
Well I have a several years experience with it in both C++ and Python (and the science/math directly). My interpretation is that, while the basics can be easy to use, the more complicated functions (Stereo Calibration, triangulation, really anything with photogrammetry) are nuanced and somewhat unforgiving. A lot of it is driven by poor examples and the poor documentation on what you’re actually getting. For example, it doesn’t talk about what units is a particular return value is in? Distance units or a some normalized unit? What’s expected as the input? A vector of vectors of a custom cv::Point2f two dimension float type. Stack overflow is filled with questions where people don’t get much help and their answers are met more with theory photogrammetry and I never see actual usage help or answers. It’s just like the documentation: theory heavy, usage thin, typing vague. A more… user friendly library with thorough usage documentation would be very popular if it was genuinely easy to use.
I’m sure you see where this is going but please let me finish:
Ada is the language of reliability and safety. Look at the popular and booming Tech industries, two relevant highlights are Autonomous Vehicles and Augmented Reality. Both use imaging processing and photogrammetric techniques. If an ADA based package or library that was easily usable and accurate, while having the reliability and safety of ADA, it could bring a lot of new people, companies, and industries to the language.
So anyways, the idea is AdaCV. A potentially slimmer but more easily usable and user friendly OpenCV in Ada.
Anyone working on that? Anyone finished it? Thoughts? Objections?
7 posts - 4 participants
Got stuck on part 1 because I had my unit test script using yesterday’s input!
Part 2 went okay, just required some careful reading.
Nothing about my solution feels optimal in terms of CPU cycles. Looking forward to seeing how everyone else decides to model this one.
5 posts - 3 participants
I spent most of the time fiddling with parsing. I’m sure there’s an easier way.
8 posts - 3 participants
Hello here,
Today AdaCore announced a second edition of the Advent of Ada/SPARK charity event. For each person completing one of the Advent of Code challenges using the Ada programming language, AdaCore will donate $10 to the Ada Developers Academy, up to a total of $5,000. And for those willing to go an extra mile, AdaCore will donate $20 if the solution is implemented in SPARK with at least proof of absence of run-time errors (a.k.a. Silver level).
To submit your solutions, reply to this post with a line of the following format:
[<pseudonym>][<day>][<Ada or SPARK>]<link to solution source code>
For instance, if I solve the 3rd day problem using Ada:
[Fabien-Chouteau][3][Ada] https://github.com/Fabien-Chouteau/advent-of-ada/ …
And the 5th day using SPARK:
[Fabien-Chouteau][5][SPARK] https://github.com/Fabien-Choutea/advent-of-ada/ …
Happy hacking!
58 posts - 13 participants
I hope someone has a more elegant solution for part 2. spoiler
15 posts - 6 participants
Hi, I am new in this forum.
I have a problem porting ada code from Red Hat 8 (gnat 8.5.0) to Red Hat 9 (gnat 11.3.1).
The linking phase on RHEL9 fails for “Elaboration circularity detected”.
I let the ada compiler to choose the module compilation order using the following instruction:
gnatmake -c
The reason is: “unit depends on its own elaboration”
The circularity detected is: "unit invokes a construct of unit at elaboration time.
What shall I do to find the exact location of the problem?
And why this problem was not detected before using other gnat versions?
Thanks a lot
7 posts - 4 participants
I have some code that is running fine for me at home using gnat/gcc 12.2. I decided to test it out on various versions of gnat, so I fired up godbolt and tried a few. I found that starting with version 13, my code throws an exception when the program ends:
raised PROGRAM_ERROR : example.adb:4 finalize/adjust raised exception
I wanted to double check and make sure I am not doing anything illegal and 13 catches it vs 13 just having a bug. I had to make a kinda convoluted example since the original code was from a much larger code base, so apologies if the generic formals and code don’t look too practical. I spent a few hours whittling it down from the original. Full code on godbolt is here:
Code is below:
example.adb:
with Ada.Text_IO; use Ada.Text_IO;
with Test;
procedure Example is
package B is
type Instance is limited interface;
function Make return Instance is abstract;
end B;
package C is
type Instance is new B.Instance with null record;
function Make return Instance is (null record);
end C; use C;
package T is new Test(B.Instance, C.Instance, C.Make);
Thing : B.Instance'Class := T.Make(2);
begin
Put_Line("Hello World");
end Example;
test.ads:
generic
type First(<>) is abstract tagged limited private;
type Second(<>) is new First with private;
with function Make return Second is <>;
package Test is
function Make(Key : Integer) return First'Class;
private
type Some_Access is not null access function return First'Class;
function Make_Delegate return First'Class;
Thing_Access : constant Some_Access := Make_Delegate'Access;
end Test;
test.adb:
with Ada.Containers.Indefinite_Ordered_Maps;
package body Test is
package Maps is new Ada.Containers.Indefinite_Ordered_Maps
(Key_Type => Integer,
Element_Type => Some_Access);
Map : Maps.Map;
function Make(Key : Integer) return First'Class is
begin
return Map(Key).all;
end Make;
function Make_Delegate return First'Class is
begin
return Make;
end Make_Delegate;
begin
Map.Insert(2,Thing_Access);
end Test;
It’s essentially a map of function pointers (only one in this example). I had to use a wrapper function (Make_Delegate) in order to have correct accessibility to it within the generic.
7 posts - 3 participants
Hi!
? Interfaces.C.char’Size always equal to Ada.Stream.Stream_element’Size ?
If they are not the same, what are the most common sizes?
Thanks!
7 posts - 5 participants
The 28th Ada-Europe International Conference on Reliable Software Technologies (AEiC 2024) will take place in Barcelona, Spain from 11 to 14 June, and comprises different tracks and co-located events.
Submission deadlines: 15 January for journal track papers; 26 February for industrial track and work-in-progress track papers, tutorial and workshop proposals. Submit early: tutorial/workshop proposals will be evaluated ASAP, with decisions from 1 January 2024!
More information on the conference site, including an extensive list of topics, and details on the call for contributions for the various tracks.
www.ada-europe.org/conference2024
#AEiC2024 #AdaEurope #AdaProgramming
1 post - 1 participant
I wonder. Is gnatd.v a better option than
pragma preelaborate
Is preelaborate more compiler portable? Though I do not use the features that it protects against such as dynamic dispatch, so it is simply an unneeded restriction for me with Gnat. However gnatd.v seems to offer more such as in regard to uninitialised variables? Assuming it works as I had no compile issues .
see 7.7
https://docs.adacore.com/spark2014-docs/html/lrm/packages.html
2 posts - 2 participants