Changeset 536 for trunk/test


Ignore:
Timestamp:
Jun 7, 2010, 9:20:00 AM (10 years ago)
Author:
roberth
Message:

Samples are now shown in the study overview page. Also some tests are added and the bootstrap is updated to show some sample fields with a template

Location:
trunk/test/unit/dbnp/studycapturing
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/dbnp/studycapturing/EventTests.groovy

    r496 r536  
    1212    }
    1313
    14     void testSomething() {
     14    void testBelongsToGroup() {
     15        def events = [];
     16        10.times {
     17            events[ it ] = new Event(
     18                id: it,
     19                startTime: 3600,
     20                endTime: 3800
     21            )
     22            println( 'Created event ' + it );
     23        }
     24        def evGroup1 = new EventGroup(
     25            name: 'group1',
     26            events: events[0..4]
     27        )
     28        def evGroup2 = new EventGroup(
     29            name: 'group2',
     30            events: events[3..6]
     31        )
     32
     33        Set<EventGroup> set1 = new HashSet<EventGroup>();
     34        Set<EventGroup> set2 = new HashSet<EventGroup>();
     35        Set<EventGroup> setBoth = new HashSet<EventGroup>();
     36        Set<EventGroup> setEmpty = new HashSet<EventGroup>();
     37        set1.add( evGroup1 );
     38        set2.add( evGroup2 );
     39        setBoth.add( evGroup1 );
     40        setBoth.add( evGroup2 );
     41
     42        assert events[0].belongsToGroup( set1 );
     43        assert events[3].belongsToGroup( set1 );
     44        assert !events[6].belongsToGroup( set1 );
     45
     46        assert events[3].belongsToGroup( set2 );
     47        assert events[6].belongsToGroup( set2 );
     48
     49        assert !events[0].belongsToGroup( setEmpty );
     50        assert !events[8].belongsToGroup( setEmpty );
     51
     52        assert events[0].belongsToGroup( setBoth );
     53        assert events[3].belongsToGroup( setBoth );
     54        assert events[6].belongsToGroup( setBoth );
     55
     56        assert !events[7].belongsToGroup( setBoth );
    1557
    1658    }
  • trunk/test/unit/dbnp/studycapturing/StudyTests.groovy

    r496 r536  
    22
    33import grails.test.*
    4 
     4import groovy.util.GroovyTestCase
    55class StudyTests extends GrailsUnitTestCase {
    66    protected void setUp() {
     
    1212    }
    1313
    14     void testSomething() {
     14    protected void assertCollectionEquals( Collection set1, Collection set2 ) {
     15        set1.each {
     16            assert it in set2;
     17        }
     18        set2.each {
     19            assert it in set1;
     20        }
    1521
    1622    }
     23
     24    void testGetOrphanEvents() {
     25        def events = [];
     26        10.times {
     27            events[ it ] = new Event(
     28                id: it,
     29                startTime: 3600,
     30                endTime: 3800
     31            )
     32            println( 'Created event ' + it );
     33        }
     34        def evGroup1 = new EventGroup(
     35            name: 'group1',
     36            events: events[0..4]
     37        )
     38        def evGroup2 = new EventGroup(
     39            name: 'group2',
     40            events: events[3..6]
     41        )
     42
     43        // No events should give no orphan events
     44        def study1 = new Study( title: 'Studytitle 1', events: [], eventGroups: [] );
     45        assert study1.getOrphanEvents().size() == 0;
     46
     47        // Not even with a group
     48        study1.eventGroups = [ evGroup1 ];
     49        assert study1.getOrphanEvents().size() == 0;
     50
     51        // Events 0..4 are part of evGroup1
     52        study1.events = events[0..8];
     53        println(  study1.getOrphanEvents().id )
     54        println(  events[ 5..8].id )
     55       
     56        assertCollectionEquals( study1.getOrphanEvents(), events[ 5..8 ] );
     57
     58        // Remove the evGroup
     59        study1.eventGroups = [];
     60        assertCollectionEquals( study1.getOrphanEvents(), events[ 0..8 ] );
     61
     62        // Add multiple groups
     63        study1.eventGroups = [ evGroup1, evGroup2 ];
     64        assertCollectionEquals( study1.getOrphanEvents(), events[ 7..8 ] );
     65
     66        // Remove events again
     67        study1.events = [];
     68        assert study1.getOrphanEvents().size() == 0;
     69    }
    1770}
Note: See TracChangeset for help on using the changeset viewer.